const crypto = require(
'crypto'
);
function
hashStr(t) {
return
crypto.createHash(
'md5'
).update(t,
'utf8'
).digest(
'hex'
);
}
function
getPrivateKey() {
return
t.privateKey[t.publicKeyInedx % t.privateKey.length]
}
function
get_query(t) {
var
e =
""
;
if
(t.indexOf(
"?"
) > -1) {
var
n = t.substring(t.indexOf(
"?"
) + 1).split(
"&"
);
if
(n.length > 0)
for
(
var
i = 0; i < n.length; i++) {
n[i] = n[i].split(
"="
),
e += n[i][0];
for
(
var
s = 1; s < n[i].length; ++s)
e +=
"="
+ decodeURIComponent(n[i][s]).split(
"+"
).join(
" "
);
e +=
"&"
}
}
return
""
!= e && (e = e.substring(0, e.length - 1)),
e
}
function
uriSignature(e, n=!1, i=
null
) {
if
(e) {
var
s = (
null
!= i ? i : get_query(e)) ||
""
, o = !0;
if
(-1 == s.indexOf(
"pub="
) && -1 == s.indexOf(
"vv="
))
return
s || (o = !1),
s = s.toLowerCase(),
s = t.publicKey +
"&"
+ s +
"&"
+ getPrivateKey(),
n ? (e = e.substring(1)) + (o ?
"&"
:
""
) +
"vv="
+ hashStr(s) +
"&pub="
+ t.publicKey : e + (o ?
"&"
:
"?"
) +
"vv="
+ hashStr(s) +
"&pub="
+ t.publicKey
}
return
e
}
e =
".../masterplaylist/GkNIbX1AnrUvCN6DNfsNU1xyqVtGzCEk1"
t = {
publicKey :
'CJSqDZamEJ4uC2upDJTVJaylc9kS5naPcHSOcPgN6Xglc36ocZ8n6R4Q69WO6XaOCR2o61YpCp8R6Pkoc3CScfmlcJ8QcncSinoOiHWncPmQ61WSchAo6ZCp6fWQcZ4RCPM'
,
privateKey : [
"SqDZJSqDZamEJ4uC2upD"
],
publicKeyInedx: 0
}
console.log(uriSignature(e, n=!1, i=
null
))