@substrate-system/keys 0.2.12 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -3
- package/dist/_base.min.js +2 -2
- package/dist/_base.min.js.map +3 -3
- package/dist/aes/index.min.js +2 -2
- package/dist/aes/index.min.js.map +3 -3
- package/dist/browser/index.js +93 -15
- package/dist/browser/index.min.js +2 -2
- package/dist/crypto.cjs +91 -10
- package/dist/crypto.cjs.map +3 -3
- package/dist/crypto.d.ts +26 -2
- package/dist/crypto.d.ts.map +1 -1
- package/dist/crypto.js +93 -11
- package/dist/crypto.js.map +3 -3
- package/dist/crypto.min.cjs +2 -2
- package/dist/crypto.min.cjs.map +3 -3
- package/dist/crypto.min.js +2 -2
- package/dist/crypto.min.js.map +3 -3
- package/dist/ecc/index.min.js +2 -2
- package/dist/ecc/index.min.js.map +3 -3
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +2 -2
- package/dist/index.min.cjs +1 -1
- package/dist/index.min.cjs.map +2 -2
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +3 -3
- package/dist/meta.json +21 -12
- package/dist/rsa/index.min.js +2 -2
- package/dist/rsa/index.min.js.map +3 -3
- package/dist/util.cjs +1 -0
- package/dist/util.cjs.map +2 -2
- package/dist/util.d.ts +7 -5
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +1 -0
- package/dist/util.js.map +2 -2
- package/dist/util.min.cjs +1 -1
- package/dist/util.min.cjs.map +3 -3
- package/dist/util.min.js +1 -1
- package/dist/util.min.js.map +2 -2
- package/package.json +2 -2
package/dist/browser/index.js
CHANGED
|
@@ -2399,7 +2399,7 @@
|
|
|
2399
2399
|
getPublicKeyAsArrayBuffer: () => getPublicKeyAsArrayBuffer,
|
|
2400
2400
|
getPublicKeyAsUint8Array: () => getPublicKeyAsUint8Array,
|
|
2401
2401
|
publicKeyToDid: () => publicKeyToDid,
|
|
2402
|
-
verify: () =>
|
|
2402
|
+
verify: () => verify2
|
|
2403
2403
|
});
|
|
2404
2404
|
|
|
2405
2405
|
// node_modules/@substrate-system/one-webcrypto/browser.mjs
|
|
@@ -3888,14 +3888,6 @@
|
|
|
3888
3888
|
|
|
3889
3889
|
// src/crypto.ts
|
|
3890
3890
|
var import_tweetnacl = __toESM(require_nacl_fast(), 1);
|
|
3891
|
-
async function ed25519Verify({
|
|
3892
|
-
message,
|
|
3893
|
-
publicKey,
|
|
3894
|
-
signature
|
|
3895
|
-
}) {
|
|
3896
|
-
return import_tweetnacl.default.sign.detached.verify(message, signature, publicKey);
|
|
3897
|
-
}
|
|
3898
|
-
__name(ed25519Verify, "ed25519Verify");
|
|
3899
3891
|
var did = {
|
|
3900
3892
|
keyTypes: {
|
|
3901
3893
|
"bls12-381": {
|
|
@@ -3914,17 +3906,75 @@
|
|
|
3914
3906
|
}
|
|
3915
3907
|
}
|
|
3916
3908
|
};
|
|
3909
|
+
async function verify({
|
|
3910
|
+
message,
|
|
3911
|
+
publicKey,
|
|
3912
|
+
signature
|
|
3913
|
+
}) {
|
|
3914
|
+
const format2 = getAlgorithm(publicKey);
|
|
3915
|
+
const pub = didToPublicKey2(publicKey).publicKey;
|
|
3916
|
+
if (format2 === "ed25519") {
|
|
3917
|
+
return ed25519Verify({ message, publicKey: pub, signature });
|
|
3918
|
+
}
|
|
3919
|
+
if (format2 === "rsa") {
|
|
3920
|
+
return rsaVerify({ message, publicKey: pub, signature });
|
|
3921
|
+
}
|
|
3922
|
+
throw new Error("Unknown key format");
|
|
3923
|
+
}
|
|
3924
|
+
__name(verify, "verify");
|
|
3925
|
+
function getAlgorithm(did2) {
|
|
3926
|
+
try {
|
|
3927
|
+
const { type } = didToPublicKey2(did2);
|
|
3928
|
+
return type;
|
|
3929
|
+
} catch {
|
|
3930
|
+
return "unknown";
|
|
3931
|
+
}
|
|
3932
|
+
}
|
|
3933
|
+
__name(getAlgorithm, "getAlgorithm");
|
|
3934
|
+
async function ed25519Verify({
|
|
3935
|
+
message,
|
|
3936
|
+
publicKey,
|
|
3937
|
+
signature
|
|
3938
|
+
}) {
|
|
3939
|
+
let msg = message;
|
|
3940
|
+
if (typeof message === "string") {
|
|
3941
|
+
msg = fromString2(message, "utf8");
|
|
3942
|
+
}
|
|
3943
|
+
let sig = signature;
|
|
3944
|
+
if (typeof signature === "string") {
|
|
3945
|
+
sig = fromString2(signature, "base64pad");
|
|
3946
|
+
}
|
|
3947
|
+
let pub = publicKey;
|
|
3948
|
+
if (typeof publicKey === "string") {
|
|
3949
|
+
pub = didToPublicKey2(publicKey).publicKey;
|
|
3950
|
+
}
|
|
3951
|
+
console.log("Message length:", msg.length);
|
|
3952
|
+
console.log("Signature length:", sig.length, "expected: 64");
|
|
3953
|
+
console.log("Public key length:", pub.length, "expected: 32");
|
|
3954
|
+
if (pub.length !== 32) {
|
|
3955
|
+
throw new Error(`Invalid Ed25519 public key size: ${pub.length} bytes, expected 32`);
|
|
3956
|
+
}
|
|
3957
|
+
if (sig.length !== 64) {
|
|
3958
|
+
throw new Error(`Invalid Ed25519 signature size: ${sig.length} bytes, expected 64`);
|
|
3959
|
+
}
|
|
3960
|
+
return import_tweetnacl.default.sign.detached.verify(msg, sig, pub);
|
|
3961
|
+
}
|
|
3962
|
+
__name(ed25519Verify, "ed25519Verify");
|
|
3917
3963
|
async function rsaVerify({
|
|
3918
3964
|
message,
|
|
3919
3965
|
publicKey,
|
|
3920
3966
|
signature
|
|
3921
3967
|
}) {
|
|
3968
|
+
let pub = publicKey;
|
|
3969
|
+
if (typeof publicKey === "string") {
|
|
3970
|
+
pub = didToPublicKey2(publicKey).publicKey;
|
|
3971
|
+
}
|
|
3922
3972
|
return rsaOperations.verify(
|
|
3923
3973
|
message,
|
|
3924
3974
|
signature,
|
|
3925
3975
|
await webcrypto.subtle.importKey(
|
|
3926
3976
|
"spki",
|
|
3927
|
-
toArrayBuffer(
|
|
3977
|
+
toArrayBuffer(pub),
|
|
3928
3978
|
{ name: RSA_SIGN_ALGORITHM, hash: RSA_HASHING_ALGORITHM },
|
|
3929
3979
|
false,
|
|
3930
3980
|
["verify"]
|
|
@@ -4058,6 +4108,34 @@
|
|
|
4058
4108
|
return new Uint8Array(arr);
|
|
4059
4109
|
}
|
|
4060
4110
|
__name(getPublicKeyAsUint8Array, "getPublicKeyAsUint8Array");
|
|
4111
|
+
function didToPublicKey2(inputDid) {
|
|
4112
|
+
if (!inputDid.startsWith(BASE58_DID_PREFIX)) {
|
|
4113
|
+
throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");
|
|
4114
|
+
}
|
|
4115
|
+
const didWithoutPrefix = inputDid.substr(BASE58_DID_PREFIX.length);
|
|
4116
|
+
const magicalBuf = fromString2(didWithoutPrefix, "base58btc");
|
|
4117
|
+
const result = Object.entries(did.keyTypes).find(
|
|
4118
|
+
([_key, attr]) => hasPrefix(
|
|
4119
|
+
magicalBuf.buffer,
|
|
4120
|
+
attr.magicBytes.buffer
|
|
4121
|
+
)
|
|
4122
|
+
);
|
|
4123
|
+
if (!result) {
|
|
4124
|
+
throw new Error("Unsupported key algorithm.");
|
|
4125
|
+
}
|
|
4126
|
+
const rawKeyData = magicalBuf.slice(result[1].magicBytes.length);
|
|
4127
|
+
if (result[0] === "ed25519" && rawKeyData.length === 44) {
|
|
4128
|
+
return {
|
|
4129
|
+
publicKey: rawKeyData.slice(-32),
|
|
4130
|
+
type: result[0]
|
|
4131
|
+
};
|
|
4132
|
+
}
|
|
4133
|
+
return {
|
|
4134
|
+
publicKey: rawKeyData,
|
|
4135
|
+
type: result[0]
|
|
4136
|
+
};
|
|
4137
|
+
}
|
|
4138
|
+
__name(didToPublicKey2, "didToPublicKey");
|
|
4061
4139
|
|
|
4062
4140
|
// src/aes/index.ts
|
|
4063
4141
|
function toArrayBuffer2(data) {
|
|
@@ -4577,7 +4655,7 @@
|
|
|
4577
4655
|
return this.decryptAsString(msg, keysize);
|
|
4578
4656
|
}, "asString")
|
|
4579
4657
|
});
|
|
4580
|
-
async function
|
|
4658
|
+
async function verify2(msg, sig, signingDid) {
|
|
4581
4659
|
const _key = didToPublicKey(signingDid);
|
|
4582
4660
|
const key = await importPublicKey(
|
|
4583
4661
|
toArrayBuffer3(_key.publicKey),
|
|
@@ -4591,7 +4669,7 @@
|
|
|
4591
4669
|
return false;
|
|
4592
4670
|
}
|
|
4593
4671
|
}
|
|
4594
|
-
__name(
|
|
4672
|
+
__name(verify2, "verify");
|
|
4595
4673
|
Object.assign(RsaKeys.prototype.decryptKey, {
|
|
4596
4674
|
asString: /* @__PURE__ */ __name(async function(msg, format2) {
|
|
4597
4675
|
return this.decryptKeyAsString(msg, format2);
|
|
@@ -4662,7 +4740,7 @@
|
|
|
4662
4740
|
default: () => ecc_default,
|
|
4663
4741
|
exportPublicKey: () => exportPublicKey,
|
|
4664
4742
|
importPublicKey: () => importPublicKey2,
|
|
4665
|
-
verify: () =>
|
|
4743
|
+
verify: () => verify3
|
|
4666
4744
|
});
|
|
4667
4745
|
|
|
4668
4746
|
// src/errors.ts
|
|
@@ -4992,7 +5070,7 @@
|
|
|
4992
5070
|
return this.signAsString(msg, _charsize);
|
|
4993
5071
|
}, "asString")
|
|
4994
5072
|
});
|
|
4995
|
-
async function
|
|
5073
|
+
async function verify3(msg, sig, signingDid) {
|
|
4996
5074
|
try {
|
|
4997
5075
|
const _key = didToPublicKey(signingDid);
|
|
4998
5076
|
if (_key.type !== "ed25519") {
|
|
@@ -5032,7 +5110,7 @@
|
|
|
5032
5110
|
return false;
|
|
5033
5111
|
}
|
|
5034
5112
|
}
|
|
5035
|
-
__name(
|
|
5113
|
+
__name(verify3, "verify");
|
|
5036
5114
|
async function deriveKey(privateKey, publicKey, salt, info, keysize) {
|
|
5037
5115
|
const encoder = new TextEncoder();
|
|
5038
5116
|
const sharedSecret = await crypto.subtle.deriveBits(
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";(()=>{var _i=Object.create;var Qe=Object.defineProperty;var Ci=Object.getOwnPropertyDescriptor;var Pi=Object.getOwnPropertyNames;var Bi=Object.getPrototypeOf,Ti=Object.prototype.hasOwnProperty;var x=(t,e)=>Qe(t,"name",{value:e,configurable:!0}),Dn=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,i)=>(typeof require<"u"?require:e)[i]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var In=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Er=(t,e)=>{for(var i in e)Qe(t,i,{get:e[i],enumerable:!0})},Di=(t,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let y of Pi(e))!Ti.call(t,y)&&y!==i&&Qe(t,y,{get:()=>e[y],enumerable:!(s=Ci(e,y))||s.enumerable});return t};var Ii=(t,e,i)=>(i=t!=null?_i(Bi(t)):{},Di(e||!t||!t.__esModule?Qe(i,"default",{value:t,enumerable:!0}):i,t));var si=In(()=>{});var ci=In((xs,pt)=>{(function(t){"use strict";var e=x(function(n){var o,f=new Float64Array(16);if(n)for(o=0;o<n.length;o++)f[o]=n[o];return f},"gf"),i=x(function(){throw new Error("no PRNG")},"randombytes"),s=new Uint8Array(16),y=new Uint8Array(32);y[0]=9;var g=e(),E=e([1]),M=e([56129,1]),er=e([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),fr=e([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),ir=e([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),lr=e([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),Ir=e([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function ce(n,o,f,r){n[o]=f>>24&255,n[o+1]=f>>16&255,n[o+2]=f>>8&255,n[o+3]=f&255,n[o+4]=r>>24&255,n[o+5]=r>>16&255,n[o+6]=r>>8&255,n[o+7]=r&255}x(ce,"ts64");function $(n,o,f,r,a){var u,p=0;for(u=0;u<a;u++)p|=n[o+u]^f[r+u];return(1&p-1>>>8)-1}x($,"vn");function yr(n,o,f,r){return $(n,o,f,r,16)}x(yr,"crypto_verify_16");function Sr(n,o,f,r){return $(n,o,f,r,32)}x(Sr,"crypto_verify_32");function wr(n,o,f,r){for(var a=r[0]&255|(r[1]&255)<<8|(r[2]&255)<<16|(r[3]&255)<<24,u=f[0]&255|(f[1]&255)<<8|(f[2]&255)<<16|(f[3]&255)<<24,p=f[4]&255|(f[5]&255)<<8|(f[6]&255)<<16|(f[7]&255)<<24,b=f[8]&255|(f[9]&255)<<8|(f[10]&255)<<16|(f[11]&255)<<24,K=f[12]&255|(f[13]&255)<<8|(f[14]&255)<<16|(f[15]&255)<<24,T=r[4]&255|(r[5]&255)<<8|(r[6]&255)<<16|(r[7]&255)<<24,S=o[0]&255|(o[1]&255)<<8|(o[2]&255)<<16|(o[3]&255)<<24,J=o[4]&255|(o[5]&255)<<8|(o[6]&255)<<16|(o[7]&255)<<24,_=o[8]&255|(o[9]&255)<<8|(o[10]&255)<<16|(o[11]&255)<<24,L=o[12]&255|(o[13]&255)<<8|(o[14]&255)<<16|(o[15]&255)<<24,N=r[8]&255|(r[9]&255)<<8|(r[10]&255)<<16|(r[11]&255)<<24,H=f[16]&255|(f[17]&255)<<8|(f[18]&255)<<16|(f[19]&255)<<24,Y=f[20]&255|(f[21]&255)<<8|(f[22]&255)<<16|(f[23]&255)<<24,R=f[24]&255|(f[25]&255)<<8|(f[26]&255)<<16|(f[27]&255)<<24,O=f[28]&255|(f[29]&255)<<8|(f[30]&255)<<16|(f[31]&255)<<24,z=r[12]&255|(r[13]&255)<<8|(r[14]&255)<<16|(r[15]&255)<<24,C=a,D=u,v=p,P=b,B=K,U=T,h=S,d=J,m=_,l=L,A=N,w=H,I=Y,j=R,G=O,F=z,c,X=0;X<20;X+=2)c=C+I|0,B^=c<<7|c>>>25,c=B+C|0,m^=c<<9|c>>>23,c=m+B|0,I^=c<<13|c>>>19,c=I+m|0,C^=c<<18|c>>>14,c=U+D|0,l^=c<<7|c>>>25,c=l+U|0,j^=c<<9|c>>>23,c=j+l|0,D^=c<<13|c>>>19,c=D+j|0,U^=c<<18|c>>>14,c=A+h|0,G^=c<<7|c>>>25,c=G+A|0,v^=c<<9|c>>>23,c=v+G|0,h^=c<<13|c>>>19,c=h+v|0,A^=c<<18|c>>>14,c=F+w|0,P^=c<<7|c>>>25,c=P+F|0,d^=c<<9|c>>>23,c=d+P|0,w^=c<<13|c>>>19,c=w+d|0,F^=c<<18|c>>>14,c=C+P|0,D^=c<<7|c>>>25,c=D+C|0,v^=c<<9|c>>>23,c=v+D|0,P^=c<<13|c>>>19,c=P+v|0,C^=c<<18|c>>>14,c=U+B|0,h^=c<<7|c>>>25,c=h+U|0,d^=c<<9|c>>>23,c=d+h|0,B^=c<<13|c>>>19,c=B+d|0,U^=c<<18|c>>>14,c=A+l|0,w^=c<<7|c>>>25,c=w+A|0,m^=c<<9|c>>>23,c=m+w|0,l^=c<<13|c>>>19,c=l+m|0,A^=c<<18|c>>>14,c=F+G|0,I^=c<<7|c>>>25,c=I+F|0,j^=c<<9|c>>>23,c=j+I|0,G^=c<<13|c>>>19,c=G+j|0,F^=c<<18|c>>>14;C=C+a|0,D=D+u|0,v=v+p|0,P=P+b|0,B=B+K|0,U=U+T|0,h=h+S|0,d=d+J|0,m=m+_|0,l=l+L|0,A=A+N|0,w=w+H|0,I=I+Y|0,j=j+R|0,G=G+O|0,F=F+z|0,n[0]=C>>>0&255,n[1]=C>>>8&255,n[2]=C>>>16&255,n[3]=C>>>24&255,n[4]=D>>>0&255,n[5]=D>>>8&255,n[6]=D>>>16&255,n[7]=D>>>24&255,n[8]=v>>>0&255,n[9]=v>>>8&255,n[10]=v>>>16&255,n[11]=v>>>24&255,n[12]=P>>>0&255,n[13]=P>>>8&255,n[14]=P>>>16&255,n[15]=P>>>24&255,n[16]=B>>>0&255,n[17]=B>>>8&255,n[18]=B>>>16&255,n[19]=B>>>24&255,n[20]=U>>>0&255,n[21]=U>>>8&255,n[22]=U>>>16&255,n[23]=U>>>24&255,n[24]=h>>>0&255,n[25]=h>>>8&255,n[26]=h>>>16&255,n[27]=h>>>24&255,n[28]=d>>>0&255,n[29]=d>>>8&255,n[30]=d>>>16&255,n[31]=d>>>24&255,n[32]=m>>>0&255,n[33]=m>>>8&255,n[34]=m>>>16&255,n[35]=m>>>24&255,n[36]=l>>>0&255,n[37]=l>>>8&255,n[38]=l>>>16&255,n[39]=l>>>24&255,n[40]=A>>>0&255,n[41]=A>>>8&255,n[42]=A>>>16&255,n[43]=A>>>24&255,n[44]=w>>>0&255,n[45]=w>>>8&255,n[46]=w>>>16&255,n[47]=w>>>24&255,n[48]=I>>>0&255,n[49]=I>>>8&255,n[50]=I>>>16&255,n[51]=I>>>24&255,n[52]=j>>>0&255,n[53]=j>>>8&255,n[54]=j>>>16&255,n[55]=j>>>24&255,n[56]=G>>>0&255,n[57]=G>>>8&255,n[58]=G>>>16&255,n[59]=G>>>24&255,n[60]=F>>>0&255,n[61]=F>>>8&255,n[62]=F>>>16&255,n[63]=F>>>24&255}x(wr,"core_salsa20");function dr(n,o,f,r){for(var a=r[0]&255|(r[1]&255)<<8|(r[2]&255)<<16|(r[3]&255)<<24,u=f[0]&255|(f[1]&255)<<8|(f[2]&255)<<16|(f[3]&255)<<24,p=f[4]&255|(f[5]&255)<<8|(f[6]&255)<<16|(f[7]&255)<<24,b=f[8]&255|(f[9]&255)<<8|(f[10]&255)<<16|(f[11]&255)<<24,K=f[12]&255|(f[13]&255)<<8|(f[14]&255)<<16|(f[15]&255)<<24,T=r[4]&255|(r[5]&255)<<8|(r[6]&255)<<16|(r[7]&255)<<24,S=o[0]&255|(o[1]&255)<<8|(o[2]&255)<<16|(o[3]&255)<<24,J=o[4]&255|(o[5]&255)<<8|(o[6]&255)<<16|(o[7]&255)<<24,_=o[8]&255|(o[9]&255)<<8|(o[10]&255)<<16|(o[11]&255)<<24,L=o[12]&255|(o[13]&255)<<8|(o[14]&255)<<16|(o[15]&255)<<24,N=r[8]&255|(r[9]&255)<<8|(r[10]&255)<<16|(r[11]&255)<<24,H=f[16]&255|(f[17]&255)<<8|(f[18]&255)<<16|(f[19]&255)<<24,Y=f[20]&255|(f[21]&255)<<8|(f[22]&255)<<16|(f[23]&255)<<24,R=f[24]&255|(f[25]&255)<<8|(f[26]&255)<<16|(f[27]&255)<<24,O=f[28]&255|(f[29]&255)<<8|(f[30]&255)<<16|(f[31]&255)<<24,z=r[12]&255|(r[13]&255)<<8|(r[14]&255)<<16|(r[15]&255)<<24,C=a,D=u,v=p,P=b,B=K,U=T,h=S,d=J,m=_,l=L,A=N,w=H,I=Y,j=R,G=O,F=z,c,X=0;X<20;X+=2)c=C+I|0,B^=c<<7|c>>>25,c=B+C|0,m^=c<<9|c>>>23,c=m+B|0,I^=c<<13|c>>>19,c=I+m|0,C^=c<<18|c>>>14,c=U+D|0,l^=c<<7|c>>>25,c=l+U|0,j^=c<<9|c>>>23,c=j+l|0,D^=c<<13|c>>>19,c=D+j|0,U^=c<<18|c>>>14,c=A+h|0,G^=c<<7|c>>>25,c=G+A|0,v^=c<<9|c>>>23,c=v+G|0,h^=c<<13|c>>>19,c=h+v|0,A^=c<<18|c>>>14,c=F+w|0,P^=c<<7|c>>>25,c=P+F|0,d^=c<<9|c>>>23,c=d+P|0,w^=c<<13|c>>>19,c=w+d|0,F^=c<<18|c>>>14,c=C+P|0,D^=c<<7|c>>>25,c=D+C|0,v^=c<<9|c>>>23,c=v+D|0,P^=c<<13|c>>>19,c=P+v|0,C^=c<<18|c>>>14,c=U+B|0,h^=c<<7|c>>>25,c=h+U|0,d^=c<<9|c>>>23,c=d+h|0,B^=c<<13|c>>>19,c=B+d|0,U^=c<<18|c>>>14,c=A+l|0,w^=c<<7|c>>>25,c=w+A|0,m^=c<<9|c>>>23,c=m+w|0,l^=c<<13|c>>>19,c=l+m|0,A^=c<<18|c>>>14,c=F+G|0,I^=c<<7|c>>>25,c=I+F|0,j^=c<<9|c>>>23,c=j+I|0,G^=c<<13|c>>>19,c=G+j|0,F^=c<<18|c>>>14;n[0]=C>>>0&255,n[1]=C>>>8&255,n[2]=C>>>16&255,n[3]=C>>>24&255,n[4]=U>>>0&255,n[5]=U>>>8&255,n[6]=U>>>16&255,n[7]=U>>>24&255,n[8]=A>>>0&255,n[9]=A>>>8&255,n[10]=A>>>16&255,n[11]=A>>>24&255,n[12]=F>>>0&255,n[13]=F>>>8&255,n[14]=F>>>16&255,n[15]=F>>>24&255,n[16]=h>>>0&255,n[17]=h>>>8&255,n[18]=h>>>16&255,n[19]=h>>>24&255,n[20]=d>>>0&255,n[21]=d>>>8&255,n[22]=d>>>16&255,n[23]=d>>>24&255,n[24]=m>>>0&255,n[25]=m>>>8&255,n[26]=m>>>16&255,n[27]=m>>>24&255,n[28]=l>>>0&255,n[29]=l>>>8&255,n[30]=l>>>16&255,n[31]=l>>>24&255}x(dr,"core_hsalsa20");function Kr(n,o,f,r){wr(n,o,f,r)}x(Kr,"crypto_core_salsa20");function gr(n,o,f,r){dr(n,o,f,r)}x(gr,"crypto_core_hsalsa20");var hr=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function Mr(n,o,f,r,a,u,p){var b=new Uint8Array(16),K=new Uint8Array(64),T,S;for(S=0;S<16;S++)b[S]=0;for(S=0;S<8;S++)b[S]=u[S];for(;a>=64;){for(Kr(K,b,p,hr),S=0;S<64;S++)n[o+S]=f[r+S]^K[S];for(T=1,S=8;S<16;S++)T=T+(b[S]&255)|0,b[S]=T&255,T>>>=8;a-=64,o+=64,r+=64}if(a>0)for(Kr(K,b,p,hr),S=0;S<a;S++)n[o+S]=f[r+S]^K[S];return 0}x(Mr,"crypto_stream_salsa20_xor");function vr(n,o,f,r,a){var u=new Uint8Array(16),p=new Uint8Array(64),b,K;for(K=0;K<16;K++)u[K]=0;for(K=0;K<8;K++)u[K]=r[K];for(;f>=64;){for(Kr(p,u,a,hr),K=0;K<64;K++)n[o+K]=p[K];for(b=1,K=8;K<16;K++)b=b+(u[K]&255)|0,u[K]=b&255,b>>>=8;f-=64,o+=64}if(f>0)for(Kr(p,u,a,hr),K=0;K<f;K++)n[o+K]=p[K];return 0}x(vr,"crypto_stream_salsa20");function Br(n,o,f,r,a){var u=new Uint8Array(32);gr(u,r,a,hr);for(var p=new Uint8Array(8),b=0;b<8;b++)p[b]=r[b+16];return vr(n,o,f,p,u)}x(Br,"crypto_stream");function Zr(n,o,f,r,a,u,p){var b=new Uint8Array(32);gr(b,u,p,hr);for(var K=new Uint8Array(8),T=0;T<8;T++)K[T]=u[T+16];return Mr(n,o,f,r,a,K,b)}x(Zr,"crypto_stream_xor");var Ge=x(function(n){this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.leftover=0,this.fin=0;var o,f,r,a,u,p,b,K;o=n[0]&255|(n[1]&255)<<8,this.r[0]=o&8191,f=n[2]&255|(n[3]&255)<<8,this.r[1]=(o>>>13|f<<3)&8191,r=n[4]&255|(n[5]&255)<<8,this.r[2]=(f>>>10|r<<6)&7939,a=n[6]&255|(n[7]&255)<<8,this.r[3]=(r>>>7|a<<9)&8191,u=n[8]&255|(n[9]&255)<<8,this.r[4]=(a>>>4|u<<12)&255,this.r[5]=u>>>1&8190,p=n[10]&255|(n[11]&255)<<8,this.r[6]=(u>>>14|p<<2)&8191,b=n[12]&255|(n[13]&255)<<8,this.r[7]=(p>>>11|b<<5)&8065,K=n[14]&255|(n[15]&255)<<8,this.r[8]=(b>>>8|K<<8)&8191,this.r[9]=K>>>5&127,this.pad[0]=n[16]&255|(n[17]&255)<<8,this.pad[1]=n[18]&255|(n[19]&255)<<8,this.pad[2]=n[20]&255|(n[21]&255)<<8,this.pad[3]=n[22]&255|(n[23]&255)<<8,this.pad[4]=n[24]&255|(n[25]&255)<<8,this.pad[5]=n[26]&255|(n[27]&255)<<8,this.pad[6]=n[28]&255|(n[29]&255)<<8,this.pad[7]=n[30]&255|(n[31]&255)<<8},"poly1305");Ge.prototype.blocks=function(n,o,f){for(var r=this.fin?0:2048,a,u,p,b,K,T,S,J,_,L,N,H,Y,R,O,z,C,D,v,P=this.h[0],B=this.h[1],U=this.h[2],h=this.h[3],d=this.h[4],m=this.h[5],l=this.h[6],A=this.h[7],w=this.h[8],I=this.h[9],j=this.r[0],G=this.r[1],F=this.r[2],c=this.r[3],X=this.r[4],Q=this.r[5],rr=this.r[6],V=this.r[7],Z=this.r[8],q=this.r[9];f>=16;)a=n[o+0]&255|(n[o+1]&255)<<8,P+=a&8191,u=n[o+2]&255|(n[o+3]&255)<<8,B+=(a>>>13|u<<3)&8191,p=n[o+4]&255|(n[o+5]&255)<<8,U+=(u>>>10|p<<6)&8191,b=n[o+6]&255|(n[o+7]&255)<<8,h+=(p>>>7|b<<9)&8191,K=n[o+8]&255|(n[o+9]&255)<<8,d+=(b>>>4|K<<12)&8191,m+=K>>>1&8191,T=n[o+10]&255|(n[o+11]&255)<<8,l+=(K>>>14|T<<2)&8191,S=n[o+12]&255|(n[o+13]&255)<<8,A+=(T>>>11|S<<5)&8191,J=n[o+14]&255|(n[o+15]&255)<<8,w+=(S>>>8|J<<8)&8191,I+=J>>>5|r,_=0,L=_,L+=P*j,L+=B*(5*q),L+=U*(5*Z),L+=h*(5*V),L+=d*(5*rr),_=L>>>13,L&=8191,L+=m*(5*Q),L+=l*(5*X),L+=A*(5*c),L+=w*(5*F),L+=I*(5*G),_+=L>>>13,L&=8191,N=_,N+=P*G,N+=B*j,N+=U*(5*q),N+=h*(5*Z),N+=d*(5*V),_=N>>>13,N&=8191,N+=m*(5*rr),N+=l*(5*Q),N+=A*(5*X),N+=w*(5*c),N+=I*(5*F),_+=N>>>13,N&=8191,H=_,H+=P*F,H+=B*G,H+=U*j,H+=h*(5*q),H+=d*(5*Z),_=H>>>13,H&=8191,H+=m*(5*V),H+=l*(5*rr),H+=A*(5*Q),H+=w*(5*X),H+=I*(5*c),_+=H>>>13,H&=8191,Y=_,Y+=P*c,Y+=B*F,Y+=U*G,Y+=h*j,Y+=d*(5*q),_=Y>>>13,Y&=8191,Y+=m*(5*Z),Y+=l*(5*V),Y+=A*(5*rr),Y+=w*(5*Q),Y+=I*(5*X),_+=Y>>>13,Y&=8191,R=_,R+=P*X,R+=B*c,R+=U*F,R+=h*G,R+=d*j,_=R>>>13,R&=8191,R+=m*(5*q),R+=l*(5*Z),R+=A*(5*V),R+=w*(5*rr),R+=I*(5*Q),_+=R>>>13,R&=8191,O=_,O+=P*Q,O+=B*X,O+=U*c,O+=h*F,O+=d*G,_=O>>>13,O&=8191,O+=m*j,O+=l*(5*q),O+=A*(5*Z),O+=w*(5*V),O+=I*(5*rr),_+=O>>>13,O&=8191,z=_,z+=P*rr,z+=B*Q,z+=U*X,z+=h*c,z+=d*F,_=z>>>13,z&=8191,z+=m*G,z+=l*j,z+=A*(5*q),z+=w*(5*Z),z+=I*(5*V),_+=z>>>13,z&=8191,C=_,C+=P*V,C+=B*rr,C+=U*Q,C+=h*X,C+=d*c,_=C>>>13,C&=8191,C+=m*F,C+=l*G,C+=A*j,C+=w*(5*q),C+=I*(5*Z),_+=C>>>13,C&=8191,D=_,D+=P*Z,D+=B*V,D+=U*rr,D+=h*Q,D+=d*X,_=D>>>13,D&=8191,D+=m*c,D+=l*F,D+=A*G,D+=w*j,D+=I*(5*q),_+=D>>>13,D&=8191,v=_,v+=P*q,v+=B*Z,v+=U*V,v+=h*rr,v+=d*Q,_=v>>>13,v&=8191,v+=m*X,v+=l*c,v+=A*F,v+=w*G,v+=I*j,_+=v>>>13,v&=8191,_=(_<<2)+_|0,_=_+L|0,L=_&8191,_=_>>>13,N+=_,P=L,B=N,U=H,h=Y,d=R,m=O,l=z,A=C,w=D,I=v,o+=16,f-=16;this.h[0]=P,this.h[1]=B,this.h[2]=U,this.h[3]=h,this.h[4]=d,this.h[5]=m,this.h[6]=l,this.h[7]=A,this.h[8]=w,this.h[9]=I},Ge.prototype.finish=function(n,o){var f=new Uint16Array(10),r,a,u,p;if(this.leftover){for(p=this.leftover,this.buffer[p++]=1;p<16;p++)this.buffer[p]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(r=this.h[1]>>>13,this.h[1]&=8191,p=2;p<10;p++)this.h[p]+=r,r=this.h[p]>>>13,this.h[p]&=8191;for(this.h[0]+=r*5,r=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=r,r=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=r,f[0]=this.h[0]+5,r=f[0]>>>13,f[0]&=8191,p=1;p<10;p++)f[p]=this.h[p]+r,r=f[p]>>>13,f[p]&=8191;for(f[9]-=8192,a=(r^1)-1,p=0;p<10;p++)f[p]&=a;for(a=~a,p=0;p<10;p++)this.h[p]=this.h[p]&a|f[p];for(this.h[0]=(this.h[0]|this.h[1]<<13)&65535,this.h[1]=(this.h[1]>>>3|this.h[2]<<10)&65535,this.h[2]=(this.h[2]>>>6|this.h[3]<<7)&65535,this.h[3]=(this.h[3]>>>9|this.h[4]<<4)&65535,this.h[4]=(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14)&65535,this.h[5]=(this.h[6]>>>2|this.h[7]<<11)&65535,this.h[6]=(this.h[7]>>>5|this.h[8]<<8)&65535,this.h[7]=(this.h[8]>>>8|this.h[9]<<5)&65535,u=this.h[0]+this.pad[0],this.h[0]=u&65535,p=1;p<8;p++)u=(this.h[p]+this.pad[p]|0)+(u>>>16)|0,this.h[p]=u&65535;n[o+0]=this.h[0]>>>0&255,n[o+1]=this.h[0]>>>8&255,n[o+2]=this.h[1]>>>0&255,n[o+3]=this.h[1]>>>8&255,n[o+4]=this.h[2]>>>0&255,n[o+5]=this.h[2]>>>8&255,n[o+6]=this.h[3]>>>0&255,n[o+7]=this.h[3]>>>8&255,n[o+8]=this.h[4]>>>0&255,n[o+9]=this.h[4]>>>8&255,n[o+10]=this.h[5]>>>0&255,n[o+11]=this.h[5]>>>8&255,n[o+12]=this.h[6]>>>0&255,n[o+13]=this.h[6]>>>8&255,n[o+14]=this.h[7]>>>0&255,n[o+15]=this.h[7]>>>8&255},Ge.prototype.update=function(n,o,f){var r,a;if(this.leftover){for(a=16-this.leftover,a>f&&(a=f),r=0;r<a;r++)this.buffer[this.leftover+r]=n[o+r];if(f-=a,o+=a,this.leftover+=a,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(f>=16&&(a=f-f%16,this.blocks(n,o,a),o+=a,f-=a),f){for(r=0;r<f;r++)this.buffer[this.leftover+r]=n[o+r];this.leftover+=f}};function lt(n,o,f,r,a,u){var p=new Ge(u);return p.update(f,r,a),p.finish(n,o),0}x(lt,"crypto_onetimeauth");function bn(n,o,f,r,a,u){var p=new Uint8Array(16);return lt(p,0,f,r,a,u),yr(n,o,p,0)}x(bn,"crypto_onetimeauth_verify");function bt(n,o,f,r,a){var u;if(f<32)return-1;for(Zr(n,0,o,0,f,r,a),lt(n,16,n,32,f-32,n),u=0;u<16;u++)n[u]=0;return 0}x(bt,"crypto_secretbox");function At(n,o,f,r,a){var u,p=new Uint8Array(32);if(f<32||(Br(p,0,32,r,a),bn(o,16,o,32,f-32,p)!==0))return-1;for(Zr(n,0,o,0,f,r,a),u=0;u<32;u++)n[u]=0;return 0}x(At,"crypto_secretbox_open");function Gr(n,o){var f;for(f=0;f<16;f++)n[f]=o[f]|0}x(Gr,"set25519");function mt(n){var o,f,r=1;for(o=0;o<16;o++)f=n[o]+r+65535,r=Math.floor(f/65536),n[o]=f-r*65536;n[0]+=r-1+37*(r-1)}x(mt,"car25519");function ye(n,o,f){for(var r,a=~(f-1),u=0;u<16;u++)r=a&(n[u]^o[u]),n[u]^=r,o[u]^=r}x(ye,"sel25519");function xe(n,o){var f,r,a,u=e(),p=e();for(f=0;f<16;f++)p[f]=o[f];for(mt(p),mt(p),mt(p),r=0;r<2;r++){for(u[0]=p[0]-65517,f=1;f<15;f++)u[f]=p[f]-65535-(u[f-1]>>16&1),u[f-1]&=65535;u[15]=p[15]-32767-(u[14]>>16&1),a=u[15]>>16&1,u[14]&=65535,ye(p,u,1-a)}for(f=0;f<16;f++)n[2*f]=p[f]&255,n[2*f+1]=p[f]>>8}x(xe,"pack25519");function An(n,o){var f=new Uint8Array(32),r=new Uint8Array(32);return xe(f,n),xe(r,o),Sr(f,0,r,0)}x(An,"neq25519");function mn(n){var o=new Uint8Array(32);return xe(o,n),o[0]&1}x(mn,"par25519");function wt(n,o){var f;for(f=0;f<16;f++)n[f]=o[2*f]+(o[2*f+1]<<8);n[15]&=32767}x(wt,"unpack25519");function Lr(n,o,f){for(var r=0;r<16;r++)n[r]=o[r]+f[r]}x(Lr,"A");function Nr(n,o,f){for(var r=0;r<16;r++)n[r]=o[r]-f[r]}x(Nr,"Z");function W(n,o,f){var r,a,u=0,p=0,b=0,K=0,T=0,S=0,J=0,_=0,L=0,N=0,H=0,Y=0,R=0,O=0,z=0,C=0,D=0,v=0,P=0,B=0,U=0,h=0,d=0,m=0,l=0,A=0,w=0,I=0,j=0,G=0,F=0,c=f[0],X=f[1],Q=f[2],rr=f[3],V=f[4],Z=f[5],q=f[6],xr=f[7],tr=f[8],or=f[9],ar=f[10],sr=f[11],pr=f[12],br=f[13],Ar=f[14],mr=f[15];r=o[0],u+=r*c,p+=r*X,b+=r*Q,K+=r*rr,T+=r*V,S+=r*Z,J+=r*q,_+=r*xr,L+=r*tr,N+=r*or,H+=r*ar,Y+=r*sr,R+=r*pr,O+=r*br,z+=r*Ar,C+=r*mr,r=o[1],p+=r*c,b+=r*X,K+=r*Q,T+=r*rr,S+=r*V,J+=r*Z,_+=r*q,L+=r*xr,N+=r*tr,H+=r*or,Y+=r*ar,R+=r*sr,O+=r*pr,z+=r*br,C+=r*Ar,D+=r*mr,r=o[2],b+=r*c,K+=r*X,T+=r*Q,S+=r*rr,J+=r*V,_+=r*Z,L+=r*q,N+=r*xr,H+=r*tr,Y+=r*or,R+=r*ar,O+=r*sr,z+=r*pr,C+=r*br,D+=r*Ar,v+=r*mr,r=o[3],K+=r*c,T+=r*X,S+=r*Q,J+=r*rr,_+=r*V,L+=r*Z,N+=r*q,H+=r*xr,Y+=r*tr,R+=r*or,O+=r*ar,z+=r*sr,C+=r*pr,D+=r*br,v+=r*Ar,P+=r*mr,r=o[4],T+=r*c,S+=r*X,J+=r*Q,_+=r*rr,L+=r*V,N+=r*Z,H+=r*q,Y+=r*xr,R+=r*tr,O+=r*or,z+=r*ar,C+=r*sr,D+=r*pr,v+=r*br,P+=r*Ar,B+=r*mr,r=o[5],S+=r*c,J+=r*X,_+=r*Q,L+=r*rr,N+=r*V,H+=r*Z,Y+=r*q,R+=r*xr,O+=r*tr,z+=r*or,C+=r*ar,D+=r*sr,v+=r*pr,P+=r*br,B+=r*Ar,U+=r*mr,r=o[6],J+=r*c,_+=r*X,L+=r*Q,N+=r*rr,H+=r*V,Y+=r*Z,R+=r*q,O+=r*xr,z+=r*tr,C+=r*or,D+=r*ar,v+=r*sr,P+=r*pr,B+=r*br,U+=r*Ar,h+=r*mr,r=o[7],_+=r*c,L+=r*X,N+=r*Q,H+=r*rr,Y+=r*V,R+=r*Z,O+=r*q,z+=r*xr,C+=r*tr,D+=r*or,v+=r*ar,P+=r*sr,B+=r*pr,U+=r*br,h+=r*Ar,d+=r*mr,r=o[8],L+=r*c,N+=r*X,H+=r*Q,Y+=r*rr,R+=r*V,O+=r*Z,z+=r*q,C+=r*xr,D+=r*tr,v+=r*or,P+=r*ar,B+=r*sr,U+=r*pr,h+=r*br,d+=r*Ar,m+=r*mr,r=o[9],N+=r*c,H+=r*X,Y+=r*Q,R+=r*rr,O+=r*V,z+=r*Z,C+=r*q,D+=r*xr,v+=r*tr,P+=r*or,B+=r*ar,U+=r*sr,h+=r*pr,d+=r*br,m+=r*Ar,l+=r*mr,r=o[10],H+=r*c,Y+=r*X,R+=r*Q,O+=r*rr,z+=r*V,C+=r*Z,D+=r*q,v+=r*xr,P+=r*tr,B+=r*or,U+=r*ar,h+=r*sr,d+=r*pr,m+=r*br,l+=r*Ar,A+=r*mr,r=o[11],Y+=r*c,R+=r*X,O+=r*Q,z+=r*rr,C+=r*V,D+=r*Z,v+=r*q,P+=r*xr,B+=r*tr,U+=r*or,h+=r*ar,d+=r*sr,m+=r*pr,l+=r*br,A+=r*Ar,w+=r*mr,r=o[12],R+=r*c,O+=r*X,z+=r*Q,C+=r*rr,D+=r*V,v+=r*Z,P+=r*q,B+=r*xr,U+=r*tr,h+=r*or,d+=r*ar,m+=r*sr,l+=r*pr,A+=r*br,w+=r*Ar,I+=r*mr,r=o[13],O+=r*c,z+=r*X,C+=r*Q,D+=r*rr,v+=r*V,P+=r*Z,B+=r*q,U+=r*xr,h+=r*tr,d+=r*or,m+=r*ar,l+=r*sr,A+=r*pr,w+=r*br,I+=r*Ar,j+=r*mr,r=o[14],z+=r*c,C+=r*X,D+=r*Q,v+=r*rr,P+=r*V,B+=r*Z,U+=r*q,h+=r*xr,d+=r*tr,m+=r*or,l+=r*ar,A+=r*sr,w+=r*pr,I+=r*br,j+=r*Ar,G+=r*mr,r=o[15],C+=r*c,D+=r*X,v+=r*Q,P+=r*rr,B+=r*V,U+=r*Z,h+=r*q,d+=r*xr,m+=r*tr,l+=r*or,A+=r*ar,w+=r*sr,I+=r*pr,j+=r*br,G+=r*Ar,F+=r*mr,u+=38*D,p+=38*v,b+=38*P,K+=38*B,T+=38*U,S+=38*h,J+=38*d,_+=38*m,L+=38*l,N+=38*A,H+=38*w,Y+=38*I,R+=38*j,O+=38*G,z+=38*F,a=1,r=u+a+65535,a=Math.floor(r/65536),u=r-a*65536,r=p+a+65535,a=Math.floor(r/65536),p=r-a*65536,r=b+a+65535,a=Math.floor(r/65536),b=r-a*65536,r=K+a+65535,a=Math.floor(r/65536),K=r-a*65536,r=T+a+65535,a=Math.floor(r/65536),T=r-a*65536,r=S+a+65535,a=Math.floor(r/65536),S=r-a*65536,r=J+a+65535,a=Math.floor(r/65536),J=r-a*65536,r=_+a+65535,a=Math.floor(r/65536),_=r-a*65536,r=L+a+65535,a=Math.floor(r/65536),L=r-a*65536,r=N+a+65535,a=Math.floor(r/65536),N=r-a*65536,r=H+a+65535,a=Math.floor(r/65536),H=r-a*65536,r=Y+a+65535,a=Math.floor(r/65536),Y=r-a*65536,r=R+a+65535,a=Math.floor(r/65536),R=r-a*65536,r=O+a+65535,a=Math.floor(r/65536),O=r-a*65536,r=z+a+65535,a=Math.floor(r/65536),z=r-a*65536,r=C+a+65535,a=Math.floor(r/65536),C=r-a*65536,u+=a-1+37*(a-1),a=1,r=u+a+65535,a=Math.floor(r/65536),u=r-a*65536,r=p+a+65535,a=Math.floor(r/65536),p=r-a*65536,r=b+a+65535,a=Math.floor(r/65536),b=r-a*65536,r=K+a+65535,a=Math.floor(r/65536),K=r-a*65536,r=T+a+65535,a=Math.floor(r/65536),T=r-a*65536,r=S+a+65535,a=Math.floor(r/65536),S=r-a*65536,r=J+a+65535,a=Math.floor(r/65536),J=r-a*65536,r=_+a+65535,a=Math.floor(r/65536),_=r-a*65536,r=L+a+65535,a=Math.floor(r/65536),L=r-a*65536,r=N+a+65535,a=Math.floor(r/65536),N=r-a*65536,r=H+a+65535,a=Math.floor(r/65536),H=r-a*65536,r=Y+a+65535,a=Math.floor(r/65536),Y=r-a*65536,r=R+a+65535,a=Math.floor(r/65536),R=r-a*65536,r=O+a+65535,a=Math.floor(r/65536),O=r-a*65536,r=z+a+65535,a=Math.floor(r/65536),z=r-a*65536,r=C+a+65535,a=Math.floor(r/65536),C=r-a*65536,u+=a-1+37*(a-1),n[0]=u,n[1]=p,n[2]=b,n[3]=K,n[4]=T,n[5]=S,n[6]=J,n[7]=_,n[8]=L,n[9]=N,n[10]=H,n[11]=Y,n[12]=R,n[13]=O,n[14]=z,n[15]=C}x(W,"M");function Tr(n,o){W(n,o,o)}x(Tr,"S");function wn(n,o){var f=e(),r;for(r=0;r<16;r++)f[r]=o[r];for(r=253;r>=0;r--)Tr(f,f),r!==2&&r!==4&&W(f,f,o);for(r=0;r<16;r++)n[r]=f[r]}x(wn,"inv25519");function Kn(n,o){var f=e(),r;for(r=0;r<16;r++)f[r]=o[r];for(r=250;r>=0;r--)Tr(f,f),r!==1&&W(f,f,o);for(r=0;r<16;r++)n[r]=f[r]}x(Kn,"pow2523");function Ve(n,o,f){var r=new Uint8Array(32),a=new Float64Array(80),u,p,b=e(),K=e(),T=e(),S=e(),J=e(),_=e();for(p=0;p<31;p++)r[p]=o[p];for(r[31]=o[31]&127|64,r[0]&=248,wt(a,f),p=0;p<16;p++)K[p]=a[p],S[p]=b[p]=T[p]=0;for(b[0]=S[0]=1,p=254;p>=0;--p)u=r[p>>>3]>>>(p&7)&1,ye(b,K,u),ye(T,S,u),Lr(J,b,T),Nr(b,b,T),Lr(T,K,S),Nr(K,K,S),Tr(S,J),Tr(_,b),W(b,T,b),W(T,K,J),Lr(J,b,T),Nr(b,b,T),Tr(K,b),Nr(T,S,_),W(b,T,M),Lr(b,b,S),W(T,T,b),W(b,S,_),W(S,K,a),Tr(K,J),ye(b,K,u),ye(T,S,u);for(p=0;p<16;p++)a[p+16]=b[p],a[p+32]=T[p],a[p+48]=K[p],a[p+64]=S[p];var L=a.subarray(32),N=a.subarray(16);return wn(L,L),W(N,N,L),xe(n,N),0}x(Ve,"crypto_scalarmult");function Xe(n,o){return Ve(n,o,y)}x(Xe,"crypto_scalarmult_base");function En(n,o){return i(o,32),Xe(n,o)}x(En,"crypto_box_keypair");function ke(n,o,f){var r=new Uint8Array(32);return Ve(r,f,o),gr(n,s,r,hr)}x(ke,"crypto_box_beforenm");var Un=bt,mi=At;function wi(n,o,f,r,a,u){var p=new Uint8Array(32);return ke(p,a,u),Un(n,o,f,r,p)}x(wi,"crypto_box");function Ki(n,o,f,r,a,u){var p=new Uint8Array(32);return ke(p,a,u),mi(n,o,f,r,p)}x(Ki,"crypto_box_open");var Sn=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function vn(n,o,f,r){for(var a=new Int32Array(16),u=new Int32Array(16),p,b,K,T,S,J,_,L,N,H,Y,R,O,z,C,D,v,P,B,U,h,d,m,l,A,w,I=n[0],j=n[1],G=n[2],F=n[3],c=n[4],X=n[5],Q=n[6],rr=n[7],V=o[0],Z=o[1],q=o[2],xr=o[3],tr=o[4],or=o[5],ar=o[6],sr=o[7],pr=0;r>=128;){for(B=0;B<16;B++)U=8*B+pr,a[B]=f[U+0]<<24|f[U+1]<<16|f[U+2]<<8|f[U+3],u[B]=f[U+4]<<24|f[U+5]<<16|f[U+6]<<8|f[U+7];for(B=0;B<80;B++)if(p=I,b=j,K=G,T=F,S=c,J=X,_=Q,L=rr,N=V,H=Z,Y=q,R=xr,O=tr,z=or,C=ar,D=sr,h=rr,d=sr,m=d&65535,l=d>>>16,A=h&65535,w=h>>>16,h=(c>>>14|tr<<18)^(c>>>18|tr<<14)^(tr>>>9|c<<23),d=(tr>>>14|c<<18)^(tr>>>18|c<<14)^(c>>>9|tr<<23),m+=d&65535,l+=d>>>16,A+=h&65535,w+=h>>>16,h=c&X^~c&Q,d=tr&or^~tr&ar,m+=d&65535,l+=d>>>16,A+=h&65535,w+=h>>>16,h=Sn[B*2],d=Sn[B*2+1],m+=d&65535,l+=d>>>16,A+=h&65535,w+=h>>>16,h=a[B%16],d=u[B%16],m+=d&65535,l+=d>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,v=A&65535|w<<16,P=m&65535|l<<16,h=v,d=P,m=d&65535,l=d>>>16,A=h&65535,w=h>>>16,h=(I>>>28|V<<4)^(V>>>2|I<<30)^(V>>>7|I<<25),d=(V>>>28|I<<4)^(I>>>2|V<<30)^(I>>>7|V<<25),m+=d&65535,l+=d>>>16,A+=h&65535,w+=h>>>16,h=I&j^I&G^j&G,d=V&Z^V&q^Z&q,m+=d&65535,l+=d>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,L=A&65535|w<<16,D=m&65535|l<<16,h=T,d=R,m=d&65535,l=d>>>16,A=h&65535,w=h>>>16,h=v,d=P,m+=d&65535,l+=d>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,T=A&65535|w<<16,R=m&65535|l<<16,j=p,G=b,F=K,c=T,X=S,Q=J,rr=_,I=L,Z=N,q=H,xr=Y,tr=R,or=O,ar=z,sr=C,V=D,B%16===15)for(U=0;U<16;U++)h=a[U],d=u[U],m=d&65535,l=d>>>16,A=h&65535,w=h>>>16,h=a[(U+9)%16],d=u[(U+9)%16],m+=d&65535,l+=d>>>16,A+=h&65535,w+=h>>>16,v=a[(U+1)%16],P=u[(U+1)%16],h=(v>>>1|P<<31)^(v>>>8|P<<24)^v>>>7,d=(P>>>1|v<<31)^(P>>>8|v<<24)^(P>>>7|v<<25),m+=d&65535,l+=d>>>16,A+=h&65535,w+=h>>>16,v=a[(U+14)%16],P=u[(U+14)%16],h=(v>>>19|P<<13)^(P>>>29|v<<3)^v>>>6,d=(P>>>19|v<<13)^(v>>>29|P<<3)^(P>>>6|v<<26),m+=d&65535,l+=d>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,a[U]=A&65535|w<<16,u[U]=m&65535|l<<16;h=I,d=V,m=d&65535,l=d>>>16,A=h&65535,w=h>>>16,h=n[0],d=o[0],m+=d&65535,l+=d>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,n[0]=I=A&65535|w<<16,o[0]=V=m&65535|l<<16,h=j,d=Z,m=d&65535,l=d>>>16,A=h&65535,w=h>>>16,h=n[1],d=o[1],m+=d&65535,l+=d>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,n[1]=j=A&65535|w<<16,o[1]=Z=m&65535|l<<16,h=G,d=q,m=d&65535,l=d>>>16,A=h&65535,w=h>>>16,h=n[2],d=o[2],m+=d&65535,l+=d>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,n[2]=G=A&65535|w<<16,o[2]=q=m&65535|l<<16,h=F,d=xr,m=d&65535,l=d>>>16,A=h&65535,w=h>>>16,h=n[3],d=o[3],m+=d&65535,l+=d>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,n[3]=F=A&65535|w<<16,o[3]=xr=m&65535|l<<16,h=c,d=tr,m=d&65535,l=d>>>16,A=h&65535,w=h>>>16,h=n[4],d=o[4],m+=d&65535,l+=d>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,n[4]=c=A&65535|w<<16,o[4]=tr=m&65535|l<<16,h=X,d=or,m=d&65535,l=d>>>16,A=h&65535,w=h>>>16,h=n[5],d=o[5],m+=d&65535,l+=d>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,n[5]=X=A&65535|w<<16,o[5]=or=m&65535|l<<16,h=Q,d=ar,m=d&65535,l=d>>>16,A=h&65535,w=h>>>16,h=n[6],d=o[6],m+=d&65535,l+=d>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,n[6]=Q=A&65535|w<<16,o[6]=ar=m&65535|l<<16,h=rr,d=sr,m=d&65535,l=d>>>16,A=h&65535,w=h>>>16,h=n[7],d=o[7],m+=d&65535,l+=d>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,n[7]=rr=A&65535|w<<16,o[7]=sr=m&65535|l<<16,pr+=128,r-=128}return r}x(vn,"crypto_hashblocks_hl");function te(n,o,f){var r=new Int32Array(8),a=new Int32Array(8),u=new Uint8Array(256),p,b=f;for(r[0]=1779033703,r[1]=3144134277,r[2]=1013904242,r[3]=2773480762,r[4]=1359893119,r[5]=2600822924,r[6]=528734635,r[7]=1541459225,a[0]=4089235720,a[1]=2227873595,a[2]=4271175723,a[3]=1595750129,a[4]=2917565137,a[5]=725511199,a[6]=4215389547,a[7]=327033209,vn(r,a,o,f),f%=128,p=0;p<f;p++)u[p]=o[b-f+p];for(u[f]=128,f=256-128*(f<112?1:0),u[f-9]=0,ce(u,f-8,b/536870912|0,b<<3),vn(r,a,u,f),p=0;p<8;p++)ce(n,8*p,r[p],a[p]);return 0}x(te,"crypto_hash");function We(n,o){var f=e(),r=e(),a=e(),u=e(),p=e(),b=e(),K=e(),T=e(),S=e();Nr(f,n[1],n[0]),Nr(S,o[1],o[0]),W(f,f,S),Lr(r,n[0],n[1]),Lr(S,o[0],o[1]),W(r,r,S),W(a,n[3],o[3]),W(a,a,fr),W(u,n[2],o[2]),Lr(u,u,u),Nr(p,r,f),Nr(b,u,a),Lr(K,u,a),Lr(T,r,f),W(n[0],p,b),W(n[1],T,K),W(n[2],K,b),W(n[3],p,T)}x(We,"add");function _n(n,o,f){var r;for(r=0;r<4;r++)ye(n[r],o[r],f)}x(_n,"cswap");function Kt(n,o){var f=e(),r=e(),a=e();wn(a,o[2]),W(f,o[0],a),W(r,o[1],a),xe(n,r),n[31]^=mn(f)<<7}x(Kt,"pack");function Et(n,o,f){var r,a;for(Gr(n[0],g),Gr(n[1],E),Gr(n[2],E),Gr(n[3],g),a=255;a>=0;--a)r=f[a/8|0]>>(a&7)&1,_n(n,o,r),We(o,n),We(n,n),_n(n,o,r)}x(Et,"scalarmult");function $e(n,o){var f=[e(),e(),e(),e()];Gr(f[0],ir),Gr(f[1],lr),Gr(f[2],E),W(f[3],ir,lr),Et(n,f,o)}x($e,"scalarbase");function Ut(n,o,f){var r=new Uint8Array(64),a=[e(),e(),e(),e()],u;for(f||i(o,32),te(r,o,32),r[0]&=248,r[31]&=127,r[31]|=64,$e(a,r),Kt(n,a),u=0;u<32;u++)o[u+32]=n[u];return 0}x(Ut,"crypto_sign_keypair");var Ze=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function St(n,o){var f,r,a,u;for(r=63;r>=32;--r){for(f=0,a=r-32,u=r-12;a<u;++a)o[a]+=f-16*o[r]*Ze[a-(r-32)],f=Math.floor((o[a]+128)/256),o[a]-=f*256;o[a]+=f,o[r]=0}for(f=0,a=0;a<32;a++)o[a]+=f-(o[31]>>4)*Ze[a],f=o[a]>>8,o[a]&=255;for(a=0;a<32;a++)o[a]-=f*Ze[a];for(r=0;r<32;r++)o[r+1]+=o[r]>>8,n[r]=o[r]&255}x(St,"modL");function vt(n){var o=new Float64Array(64),f;for(f=0;f<64;f++)o[f]=n[f];for(f=0;f<64;f++)n[f]=0;St(n,o)}x(vt,"reduce");function Cn(n,o,f,r){var a=new Uint8Array(64),u=new Uint8Array(64),p=new Uint8Array(64),b,K,T=new Float64Array(64),S=[e(),e(),e(),e()];te(a,r,32),a[0]&=248,a[31]&=127,a[31]|=64;var J=f+64;for(b=0;b<f;b++)n[64+b]=o[b];for(b=0;b<32;b++)n[32+b]=a[32+b];for(te(p,n.subarray(32),f+32),vt(p),$e(S,p),Kt(n,S),b=32;b<64;b++)n[b]=r[b];for(te(u,n,f+64),vt(u),b=0;b<64;b++)T[b]=0;for(b=0;b<32;b++)T[b]=p[b];for(b=0;b<32;b++)for(K=0;K<32;K++)T[b+K]+=u[b]*a[K];return St(n.subarray(32),T),J}x(Cn,"crypto_sign");function Ei(n,o){var f=e(),r=e(),a=e(),u=e(),p=e(),b=e(),K=e();return Gr(n[2],E),wt(n[1],o),Tr(a,n[1]),W(u,a,er),Nr(a,a,n[2]),Lr(u,n[2],u),Tr(p,u),Tr(b,p),W(K,b,p),W(f,K,a),W(f,f,u),Kn(f,f),W(f,f,a),W(f,f,u),W(f,f,u),W(n[0],f,u),Tr(r,n[0]),W(r,r,u),An(r,a)&&W(n[0],n[0],Ir),Tr(r,n[0]),W(r,r,u),An(r,a)?-1:(mn(n[0])===o[31]>>7&&Nr(n[0],g,n[0]),W(n[3],n[0],n[1]),0)}x(Ei,"unpackneg");function _t(n,o,f,r){var a,u=new Uint8Array(32),p=new Uint8Array(64),b=[e(),e(),e(),e()],K=[e(),e(),e(),e()];if(f<64||Ei(K,r))return-1;for(a=0;a<f;a++)n[a]=o[a];for(a=0;a<32;a++)n[a+32]=r[a];if(te(p,n,f),vt(p),Et(b,K,p),$e(K,o.subarray(32)),We(b,K),Kt(u,b),f-=64,Sr(o,0,u,0)){for(a=0;a<f;a++)n[a]=0;return-1}for(a=0;a<f;a++)n[a]=o[a+64];return f}x(_t,"crypto_sign_open");var Ct=32,qe=24,ve=32,ue=16,_e=32,Je=32,Ce=32,Pe=32,Pt=32,Pn=qe,Ui=ve,Si=ue,Vr=64,ne=32,pe=64,Bt=32,Tt=64;t.lowlevel={crypto_core_hsalsa20:gr,crypto_stream_xor:Zr,crypto_stream:Br,crypto_stream_salsa20_xor:Mr,crypto_stream_salsa20:vr,crypto_onetimeauth:lt,crypto_onetimeauth_verify:bn,crypto_verify_16:yr,crypto_verify_32:Sr,crypto_secretbox:bt,crypto_secretbox_open:At,crypto_scalarmult:Ve,crypto_scalarmult_base:Xe,crypto_box_beforenm:ke,crypto_box_afternm:Un,crypto_box:wi,crypto_box_open:Ki,crypto_box_keypair:En,crypto_hash:te,crypto_sign:Cn,crypto_sign_keypair:Ut,crypto_sign_open:_t,crypto_secretbox_KEYBYTES:Ct,crypto_secretbox_NONCEBYTES:qe,crypto_secretbox_ZEROBYTES:ve,crypto_secretbox_BOXZEROBYTES:ue,crypto_scalarmult_BYTES:_e,crypto_scalarmult_SCALARBYTES:Je,crypto_box_PUBLICKEYBYTES:Ce,crypto_box_SECRETKEYBYTES:Pe,crypto_box_BEFORENMBYTES:Pt,crypto_box_NONCEBYTES:Pn,crypto_box_ZEROBYTES:Ui,crypto_box_BOXZEROBYTES:Si,crypto_sign_BYTES:Vr,crypto_sign_PUBLICKEYBYTES:ne,crypto_sign_SECRETKEYBYTES:pe,crypto_sign_SEEDBYTES:Bt,crypto_hash_BYTES:Tt,gf:e,D:er,L:Ze,pack25519:xe,unpack25519:wt,M:W,A:Lr,S:Tr,Z:Nr,pow2523:Kn,add:We,set25519:Gr,modL:St,scalarmult:Et,scalarbase:$e};function Bn(n,o){if(n.length!==Ct)throw new Error("bad key size");if(o.length!==qe)throw new Error("bad nonce size")}x(Bn,"checkLengths");function vi(n,o){if(n.length!==Ce)throw new Error("bad public key size");if(o.length!==Pe)throw new Error("bad secret key size")}x(vi,"checkBoxLengths");function Cr(){for(var n=0;n<arguments.length;n++)if(!(arguments[n]instanceof Uint8Array))throw new TypeError("unexpected type, use Uint8Array")}x(Cr,"checkArrayTypes");function Tn(n){for(var o=0;o<n.length;o++)n[o]=0}x(Tn,"cleanup"),t.randomBytes=function(n){var o=new Uint8Array(n);return i(o,n),o},t.secretbox=function(n,o,f){Cr(n,o,f),Bn(f,o);for(var r=new Uint8Array(ve+n.length),a=new Uint8Array(r.length),u=0;u<n.length;u++)r[u+ve]=n[u];return bt(a,r,r.length,o,f),a.subarray(ue)},t.secretbox.open=function(n,o,f){Cr(n,o,f),Bn(f,o);for(var r=new Uint8Array(ue+n.length),a=new Uint8Array(r.length),u=0;u<n.length;u++)r[u+ue]=n[u];return r.length<32||At(a,r,r.length,o,f)!==0?null:a.subarray(ve)},t.secretbox.keyLength=Ct,t.secretbox.nonceLength=qe,t.secretbox.overheadLength=ue,t.scalarMult=function(n,o){if(Cr(n,o),n.length!==Je)throw new Error("bad n size");if(o.length!==_e)throw new Error("bad p size");var f=new Uint8Array(_e);return Ve(f,n,o),f},t.scalarMult.base=function(n){if(Cr(n),n.length!==Je)throw new Error("bad n size");var o=new Uint8Array(_e);return Xe(o,n),o},t.scalarMult.scalarLength=Je,t.scalarMult.groupElementLength=_e,t.box=function(n,o,f,r){var a=t.box.before(f,r);return t.secretbox(n,o,a)},t.box.before=function(n,o){Cr(n,o),vi(n,o);var f=new Uint8Array(Pt);return ke(f,n,o),f},t.box.after=t.secretbox,t.box.open=function(n,o,f,r){var a=t.box.before(f,r);return t.secretbox.open(n,o,a)},t.box.open.after=t.secretbox.open,t.box.keyPair=function(){var n=new Uint8Array(Ce),o=new Uint8Array(Pe);return En(n,o),{publicKey:n,secretKey:o}},t.box.keyPair.fromSecretKey=function(n){if(Cr(n),n.length!==Pe)throw new Error("bad secret key size");var o=new Uint8Array(Ce);return Xe(o,n),{publicKey:o,secretKey:new Uint8Array(n)}},t.box.publicKeyLength=Ce,t.box.secretKeyLength=Pe,t.box.sharedKeyLength=Pt,t.box.nonceLength=Pn,t.box.overheadLength=t.secretbox.overheadLength,t.sign=function(n,o){if(Cr(n,o),o.length!==pe)throw new Error("bad secret key size");var f=new Uint8Array(Vr+n.length);return Cn(f,n,n.length,o),f},t.sign.open=function(n,o){if(Cr(n,o),o.length!==ne)throw new Error("bad public key size");var f=new Uint8Array(n.length),r=_t(f,n,n.length,o);if(r<0)return null;for(var a=new Uint8Array(r),u=0;u<a.length;u++)a[u]=f[u];return a},t.sign.detached=function(n,o){for(var f=t.sign(n,o),r=new Uint8Array(Vr),a=0;a<r.length;a++)r[a]=f[a];return r},t.sign.detached.verify=function(n,o,f){if(Cr(n,o,f),o.length!==Vr)throw new Error("bad signature size");if(f.length!==ne)throw new Error("bad public key size");var r=new Uint8Array(Vr+n.length),a=new Uint8Array(Vr+n.length),u;for(u=0;u<Vr;u++)r[u]=o[u];for(u=0;u<n.length;u++)r[u+Vr]=n[u];return _t(a,r,r.length,f)>=0},t.sign.keyPair=function(){var n=new Uint8Array(ne),o=new Uint8Array(pe);return Ut(n,o),{publicKey:n,secretKey:o}},t.sign.keyPair.fromSecretKey=function(n){if(Cr(n),n.length!==pe)throw new Error("bad secret key size");for(var o=new Uint8Array(ne),f=0;f<o.length;f++)o[f]=n[32+f];return{publicKey:o,secretKey:new Uint8Array(n)}},t.sign.keyPair.fromSeed=function(n){if(Cr(n),n.length!==Bt)throw new Error("bad seed size");for(var o=new Uint8Array(ne),f=new Uint8Array(pe),r=0;r<32;r++)f[r]=n[r];return Ut(o,f,!0),{publicKey:o,secretKey:f}},t.sign.publicKeyLength=ne,t.sign.secretKeyLength=pe,t.sign.seedLength=Bt,t.sign.signatureLength=Vr,t.hash=function(n){Cr(n);var o=new Uint8Array(Tt);return te(o,n,n.length),o},t.hash.hashLength=Tt,t.verify=function(n,o){return Cr(n,o),n.length===0||o.length===0||n.length!==o.length?!1:$(n,0,o,0,n.length)===0},t.setPRNG=function(n){i=n},function(){var n=typeof self<"u"?self.crypto||self.msCrypto:null;if(n&&n.getRandomValues){var o=65536;t.setPRNG(function(f,r){var a,u=new Uint8Array(r);for(a=0;a<r;a+=o)n.getRandomValues(u.subarray(a,a+Math.min(r-a,o)));for(a=0;a<r;a++)f[a]=u[a];Tn(u)})}else typeof Dn<"u"&&(n=si(),n&&n.randomBytes&&t.setPRNG(function(f,r){var a,u=n.randomBytes(r);for(a=0;a<r;a++)f[a]=u[a];Tn(u)}))}()})(typeof pt<"u"&&pt.exports?pt.exports:self.nacl=self.nacl||{})});var Mn=(s=>(s[s.B1024=1024]="B1024",s[s.B2048=2048]="B2048",s[s.B4096=4096]="B4096",s))(Mn||{}),Ln=(s=>(s[s.B128=128]="B128",s[s.B192=192]="B192",s[s.B256=256]="B256",s))(Ln||{}),Nn=(i=>(i.ECC="ecc",i.RSA="rsa",i))(Nn||{}),Dt=(y=>(y.SHA_1="SHA-1",y.SHA_256="SHA-256",y.SHA_384="SHA-384",y.SHA_512="SHA-512",y))(Dt||{}),It=(y=>(y.P_256="P-256",y.P_384="P-384",y.P_521="P-521",y.X25519="X25519",y))(It||{}),ie=(s=>(s.Sign="signing",s.Exchange="exchange",s.Write="write",s))(ie||{}),Mt=(i=>(i[i.B8=8]="B8",i[i.B16=16]="B16",i))(Mt||{});var li={};Er(li,{AES_GCM:()=>Hr,BASE58_DID_PREFIX:()=>Ae,BLS_DID_PREFIX:()=>ot,DEFAULT_CHAR_SIZE:()=>Yr,DEFAULT_ECC_EXCHANGE:()=>Re,DEFAULT_ECC_EXCHANGE_CURVE:()=>Gf,DEFAULT_ECC_WRITE:()=>ze,DEFAULT_HASH_ALGORITHM:()=>oe,DEFAULT_RSA_EXCHANGE:()=>st,DEFAULT_RSA_SIZE:()=>ft,DEFAULT_RSA_WRITE:()=>ct,DEFAULT_SYMM_ALGORITHM:()=>jr,DEFAULT_SYMM_LENGTH:()=>Fr,ECC_EXCHANGE_ALG:()=>fn,ECC_EXCHANGE_NAME:()=>an,ECC_WRITE_ALG:()=>me,ECC_WRITE_NAME:()=>on,EDWARDS_DID_PREFIX:()=>at,IV_LENGTH:()=>Rr,KEY_TYPE:()=>Ne,KEY_USE:()=>ii,RSA_ALGORITHM:()=>Jr,RSA_DID_PREFIX:()=>it,RSA_HASHING_ALGORITHM:()=>nt,RSA_SIGN_ALGORITHM:()=>Qr,RsaKeys:()=>se,SALT_LENGTH:()=>zr,encrypt:()=>so,encryptKeyTo:()=>Se,encryptTo:()=>gi,getPublicKeyAsArrayBuffer:()=>$r,getPublicKeyAsUint8Array:()=>xn,publicKeyToDid:()=>He,verify:()=>ao});var Mi=globalThis||window||self,k=Mi.crypto;function Be(t=0){return new Uint8Array(t)}x(Be,"allocUnsafe");function Lt(t,e){e==null&&(e=t.reduce((y,g)=>y+g.length,0));let i=Be(e),s=0;for(let y of t)i.set(y,s),s+=y.length;return i}x(Lt,"concat");var Yt={};Er(Yt,{base10:()=>Hi});var Mo=new Uint8Array(0);function Rn(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let i=0;i<t.byteLength;i++)if(t[i]!==e[i])return!1;return!0}x(Rn,"equals");function Xr(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}x(Xr,"coerce");function zn(t){return new TextEncoder().encode(t)}x(zn,"fromString");function On(t){return new TextDecoder().decode(t)}x(On,"toString");function Ni(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var i=new Uint8Array(256),s=0;s<i.length;s++)i[s]=255;for(var y=0;y<t.length;y++){var g=t.charAt(y),E=g.charCodeAt(0);if(i[E]!==255)throw new TypeError(g+" is ambiguous");i[E]=y}var M=t.length,er=t.charAt(0),fr=Math.log(M)/Math.log(256),ir=Math.log(256)/Math.log(M);function lr($){if($ instanceof Uint8Array||(ArrayBuffer.isView($)?$=new Uint8Array($.buffer,$.byteOffset,$.byteLength):Array.isArray($)&&($=Uint8Array.from($))),!($ instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if($.length===0)return"";for(var yr=0,Sr=0,wr=0,dr=$.length;wr!==dr&&$[wr]===0;)wr++,yr++;for(var Kr=(dr-wr)*ir+1>>>0,gr=new Uint8Array(Kr);wr!==dr;){for(var hr=$[wr],Mr=0,vr=Kr-1;(hr!==0||Mr<Sr)&&vr!==-1;vr--,Mr++)hr+=256*gr[vr]>>>0,gr[vr]=hr%M>>>0,hr=hr/M>>>0;if(hr!==0)throw new Error("Non-zero carry");Sr=Mr,wr++}for(var Br=Kr-Sr;Br!==Kr&&gr[Br]===0;)Br++;for(var Zr=er.repeat(yr);Br<Kr;++Br)Zr+=t.charAt(gr[Br]);return Zr}x(lr,"encode");function Ir($){if(typeof $!="string")throw new TypeError("Expected String");if($.length===0)return new Uint8Array;var yr=0;if($[yr]!==" "){for(var Sr=0,wr=0;$[yr]===er;)Sr++,yr++;for(var dr=($.length-yr)*fr+1>>>0,Kr=new Uint8Array(dr);$[yr];){var gr=i[$.charCodeAt(yr)];if(gr===255)return;for(var hr=0,Mr=dr-1;(gr!==0||hr<wr)&&Mr!==-1;Mr--,hr++)gr+=M*Kr[Mr]>>>0,Kr[Mr]=gr%256>>>0,gr=gr/256>>>0;if(gr!==0)throw new Error("Non-zero carry");wr=hr,yr++}if($[yr]!==" "){for(var vr=dr-wr;vr!==dr&&Kr[vr]===0;)vr++;for(var Br=new Uint8Array(Sr+(dr-vr)),Zr=Sr;vr!==dr;)Br[Zr++]=Kr[vr++];return Br}}}x(Ir,"decodeUnsafe");function ce($){var yr=Ir($);if(yr)return yr;throw new Error(`Non-${e} character`)}return x(ce,"decode"),{encode:lr,decodeUnsafe:Ir,decode:ce}}x(Ni,"base");var Ri=Ni,zi=Ri,Hn=zi;var Nt=class{static{x(this,"Encoder")}name;prefix;baseEncode;constructor(e,i,s){this.name=e,this.prefix=i,this.baseEncode=s}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Rt=class{static{x(this,"Decoder")}name;prefix;baseDecode;prefixCodePoint;constructor(e,i,s){this.name=e,this.prefix=i;let y=i.codePointAt(0);if(y===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=y,this.baseDecode=s}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return jn(this,e)}},zt=class{static{x(this,"ComposedDecoder")}decoders;constructor(e){this.decoders=e}or(e){return jn(this,e)}decode(e){let i=e[0],s=this.decoders[i];if(s!=null)return s.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function jn(t,e){return new zt({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}x(jn,"or");var Ot=class{static{x(this,"Codec")}name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,i,s,y){this.name=e,this.prefix=i,this.baseEncode=s,this.baseDecode=y,this.encoder=new Nt(e,i,s),this.decoder=new Rt(e,i,y)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function he({name:t,prefix:e,encode:i,decode:s}){return new Ot(t,e,i,s)}x(he,"from");function qr({name:t,prefix:e,alphabet:i}){let{encode:s,decode:y}=Hn(i,t);return he({prefix:e,name:t,encode:s,decode:x(g=>Xr(y(g)),"decode")})}x(qr,"baseX");function Oi(t,e,i,s){let y={};for(let ir=0;ir<e.length;++ir)y[e[ir]]=ir;let g=t.length;for(;t[g-1]==="=";)--g;let E=new Uint8Array(g*i/8|0),M=0,er=0,fr=0;for(let ir=0;ir<g;++ir){let lr=y[t[ir]];if(lr===void 0)throw new SyntaxError(`Non-${s} character`);er=er<<i|lr,M+=i,M>=8&&(M-=8,E[fr++]=255&er>>M)}if(M>=i||(255&er<<8-M)!==0)throw new SyntaxError("Unexpected end of data");return E}x(Oi,"decode");function Yi(t,e,i){let s=e[e.length-1]==="=",y=(1<<i)-1,g="",E=0,M=0;for(let er=0;er<t.length;++er)for(M=M<<8|t[er],E+=8;E>i;)E-=i,g+=e[y&M>>E];if(E!==0&&(g+=e[y&M<<i-E]),s)for(;(g.length*i&7)!==0;)g+="=";return g}x(Yi,"encode");function cr({name:t,prefix:e,bitsPerChar:i,alphabet:s}){return he({prefix:e,name:t,encode(y){return Yi(y,s,i)},decode(y){return Oi(y,s,i,t)}})}x(cr,"rfc4648");var Hi=qr({prefix:"9",name:"base10",alphabet:"0123456789"});var Ht={};Er(Ht,{base16:()=>ji,base16upper:()=>Fi});var ji=cr({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Fi=cr({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var jt={};Er(jt,{base2:()=>Gi});var Gi=cr({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ft={};Er(Ft,{base256emoji:()=>$i});var Fn=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Vi=Fn.reduce((t,e,i)=>(t[i]=e,t),[]),Xi=Fn.reduce((t,e,i)=>{let s=e.codePointAt(0);if(s==null)throw new Error(`Invalid character: ${e}`);return t[s]=i,t},[]);function ki(t){return t.reduce((e,i)=>(e+=Vi[i],e),"")}x(ki,"encode");function Wi(t){let e=[];for(let i of t){let s=i.codePointAt(0);if(s==null)throw new Error(`Invalid character: ${i}`);let y=Xi[s];if(y==null)throw new Error(`Non-base256emoji character: ${i}`);e.push(y)}return new Uint8Array(e)}x(Wi,"decode");var $i=he({prefix:"\u{1F680}",name:"base256emoji",encode:ki,decode:Wi});var Gt={};Er(Gt,{base32:()=>de,base32hex:()=>Qi,base32hexpad:()=>ef,base32hexpadupper:()=>tf,base32hexupper:()=>rf,base32pad:()=>qi,base32padupper:()=>Ji,base32upper:()=>Zi,base32z:()=>nf});var de=cr({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Zi=cr({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),qi=cr({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ji=cr({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Qi=cr({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),rf=cr({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ef=cr({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),tf=cr({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),nf=cr({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Vt={};Er(Vt,{base36:()=>Te,base36upper:()=>ff});var Te=qr({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ff=qr({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Xt={};Er(Xt,{base58btc:()=>Or,base58flickr:()=>of});var Or=qr({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),of=qr({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var kt={};Er(kt,{base64:()=>af,base64pad:()=>sf,base64url:()=>cf,base64urlpad:()=>yf});var af=cr({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),sf=cr({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),cf=cr({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),yf=cr({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Wt={};Er(Wt,{base8:()=>xf});var xf=cr({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var $t={};Er($t,{identity:()=>uf});var uf=he({prefix:"\0",name:"identity",encode:x(t=>On(t),"encode"),decode:x(t=>zn(t),"decode")});var ea=new TextEncoder,ta=new TextDecoder;var qt={};Er(qt,{identity:()=>Lf});var df=Xn,Gn=128,gf=127,lf=~gf,bf=Math.pow(2,31);function Xn(t,e,i){e=e||[],i=i||0;for(var s=i;t>=bf;)e[i++]=t&255|Gn,t/=128;for(;t&lf;)e[i++]=t&255|Gn,t>>>=7;return e[i]=t|0,Xn.bytes=i-s+1,e}x(Xn,"encode");var Af=Zt,mf=128,Vn=127;function Zt(t,s){var i=0,s=s||0,y=0,g=s,E,M=t.length;do{if(g>=M)throw Zt.bytes=0,new RangeError("Could not decode varint");E=t[g++],i+=y<28?(E&Vn)<<y:(E&Vn)*Math.pow(2,y),y+=7}while(E>=mf);return Zt.bytes=g-s,i}x(Zt,"read");var wf=Math.pow(2,7),Kf=Math.pow(2,14),Ef=Math.pow(2,21),Uf=Math.pow(2,28),Sf=Math.pow(2,35),vf=Math.pow(2,42),_f=Math.pow(2,49),Cf=Math.pow(2,56),Pf=Math.pow(2,63),Bf=x(function(t){return t<wf?1:t<Kf?2:t<Ef?3:t<Uf?4:t<Sf?5:t<vf?6:t<_f?7:t<Cf?8:t<Pf?9:10},"length"),Tf={encode:df,decode:Af,encodingLength:Bf},Df=Tf,De=Df;function Ie(t,e=0){return[De.decode(t,e),De.decode.bytes]}x(Ie,"decode");function ge(t,e,i=0){return De.encode(t,e,i),e}x(ge,"encodeTo");function le(t){return De.encodingLength(t)}x(le,"encodingLength");function fe(t,e){let i=e.byteLength,s=le(t),y=s+le(i),g=new Uint8Array(y+i);return ge(t,g,0),ge(i,g,s),g.set(e,y),new be(t,i,e,g)}x(fe,"create");function kn(t){let e=Xr(t),[i,s]=Ie(e),[y,g]=Ie(e.subarray(s)),E=e.subarray(s+g);if(E.byteLength!==y)throw new Error("Incorrect length");return new be(i,y,E,e)}x(kn,"decode");function Wn(t,e){if(t===e)return!0;{let i=e;return t.code===i.code&&t.size===i.size&&i.bytes instanceof Uint8Array&&Rn(t.bytes,i.bytes)}}x(Wn,"equals");var be=class{static{x(this,"Digest")}code;size;digest;bytes;constructor(e,i,s,y){this.code=e,this.size=i,this.digest=s,this.bytes=y}};var $n=0,If="identity",Zn=Xr;function Mf(t){return fe($n,Zn(t))}x(Mf,"digest");var Lf={code:$n,name:If,encode:Zn,digest:Mf};var rn={};Er(rn,{sha256:()=>Nf,sha512:()=>Rf});function Qt({name:t,code:e,encode:i}){return new Jt(t,e,i)}x(Qt,"from");var Jt=class{static{x(this,"Hasher")}name;code;encode;constructor(e,i,s){this.name=e,this.code=i,this.encode=s}digest(e){if(e instanceof Uint8Array){let i=this.encode(e);return i instanceof Uint8Array?fe(this.code,i):i.then(s=>fe(this.code,s))}else throw Error("Unknown type, must be binary type")}};function Jn(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}x(Jn,"sha");var Nf=Qt({name:"sha2-256",code:18,encode:Jn("SHA-256")}),Rf=Qt({name:"sha2-512",code:19,encode:Jn("SHA-512")});function Qn(t,e){let{bytes:i,version:s}=t;switch(s){case 0:return Of(i,en(t),e??Or.encoder);default:return Yf(i,en(t),e??de.encoder)}}x(Qn,"format");var ri=new WeakMap;function en(t){let e=ri.get(t);if(e==null){let i=new Map;return ri.set(t,i),i}return e}x(en,"baseCache");var et=class t{static{x(this,"CID")}code;version;multihash;bytes;"/";constructor(e,i,s,y){this.code=i,this.version=e,this.multihash=s,this.bytes=y,this["/"]=y}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:i}=this;if(e!==Le)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(i.code!==Hf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(i)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:i}=this.multihash,s=fe(e,i);return t.createV1(this.code,s)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,i){let s=i;return s!=null&&e.code===s.code&&e.version===s.version&&Wn(e.multihash,s.multihash)}toString(e){return Qn(this,e)}toJSON(){return{"/":Qn(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let i=e;if(i instanceof t)return i;if(i["/"]!=null&&i["/"]===i.bytes||i.asCID===i){let{version:s,code:y,multihash:g,bytes:E}=i;return new t(s,y,g,E??ei(s,y,g.bytes))}else if(i[jf]===!0){let{version:s,multihash:y,code:g}=i,E=kn(y);return t.create(s,g,E)}else return null}static create(e,i,s){if(typeof i!="number")throw new Error("String codecs are no longer supported");if(!(s.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(i!==Le)throw new Error(`Version 0 CID must use dag-pb (code: ${Le}) block encoding`);return new t(e,i,s,s.bytes)}case 1:{let y=ei(e,i,s.bytes);return new t(e,i,s,y)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Le,e)}static createV1(e,i){return t.create(1,e,i)}static decode(e){let[i,s]=t.decodeFirst(e);if(s.length!==0)throw new Error("Incorrect length");return i}static decodeFirst(e){let i=t.inspectBytes(e),s=i.size-i.multihashSize,y=Xr(e.subarray(s,s+i.multihashSize));if(y.byteLength!==i.multihashSize)throw new Error("Incorrect length");let g=y.subarray(i.multihashSize-i.digestSize),E=new be(i.multihashCode,i.digestSize,g,y);return[i.version===0?t.createV0(E):t.createV1(i.codec,E),e.subarray(i.size)]}static inspectBytes(e){let i=0,s=x(()=>{let[lr,Ir]=Ie(e.subarray(i));return i+=Ir,lr},"next"),y=s(),g=Le;if(y===18?(y=0,i=0):g=s(),y!==0&&y!==1)throw new RangeError(`Invalid CID version ${y}`);let E=i,M=s(),er=s(),fr=i+er,ir=fr-E;return{version:y,codec:g,multihashCode:M,digestSize:er,multihashSize:ir,size:fr}}static parse(e,i){let[s,y]=zf(e,i),g=t.decode(y);if(g.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return en(g).set(s,e),g}};function zf(t,e){switch(t[0]){case"Q":{let i=e??Or;return[Or.prefix,i.decode(`${Or.prefix}${t}`)]}case Or.prefix:{let i=e??Or;return[Or.prefix,i.decode(t)]}case de.prefix:{let i=e??de;return[de.prefix,i.decode(t)]}case Te.prefix:{let i=e??Te;return[Te.prefix,i.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}x(zf,"parseCIDtoBytes");function Of(t,e,i){let{prefix:s}=i;if(s!==Or.prefix)throw Error(`Cannot string encode V0 in ${i.name} encoding`);let y=e.get(s);if(y==null){let g=i.encode(t).slice(1);return e.set(s,g),g}else return y}x(Of,"toStringV0");function Yf(t,e,i){let{prefix:s}=i,y=e.get(s);if(y==null){let g=i.encode(t);return e.set(s,g),g}else return y}x(Yf,"toStringV1");var Le=112,Hf=18;function ei(t,e,i){let s=le(t),y=s+le(e),g=new Uint8Array(y+i.byteLength);return ge(t,g,0),ge(e,g,s),g.set(i,y),g}x(ei,"encodeCID");var jf=Symbol.for("@ipld/js-cid/CID");var tn={...$t,...jt,...Wt,...Yt,...Ht,...Gt,...Vt,...Xt,...kt,...Ft},Ia={...rn,...qt};function ni(t,e,i,s){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:i},decoder:{decode:s}}}x(ni,"createCodec");var ti=ni("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),nn=ni("ascii","a",t=>{let e="a";for(let i=0;i<t.length;i++)e+=String.fromCharCode(t[i]);return e},t=>{t=t.substring(1);let e=Be(t.length);for(let i=0;i<t.length;i++)e[i]=t.charCodeAt(i);return e}),Ff={utf8:ti,"utf-8":ti,hex:tn.base16,latin1:nn,ascii:nn,binary:nn,...tn},tt=Ff;function _r(t,e="utf8"){let i=tt[e];if(i==null)throw new Error(`Unsupported encoding "${e}"`);return i.decoder.decode(`${i.prefix}${t}`)}x(_r,"fromString");function nr(t,e="utf8"){let i=tt[e];if(i==null)throw new Error(`Unsupported encoding "${e}"`);return i.encoder.encode(t).substring(1)}x(nr,"toString");var pi={};Er(pi,{AES:()=>ur,decryptBytes:()=>ui,importAesKey:()=>Ee});var Ae="did:key:z",me="Ed25519",fn="X25519",Gf="X25519",on="Ed25519",an="X25519",ii={sign:["sign","verify"],encrypt:["deriveKey","deriveBits"]},Jr="RSA-OAEP",Qr="RSASSA-PKCS1-v1_5",nt="SHA-256",it=new Uint8Array([0,245,2]),ft=2048,oe="SHA-256",Yr=8,Hr="AES-GCM",jr=Hr,Fr=256,Rr=12,ot=new Uint8Array([234,1]),at=new Uint8Array([237,1]),Ne={RSA:"rsa",Edwards:"ed25519",BLS:"bls12-381"},st="rsa-exchange-key",ct="rsa-write-key",Re="ecc-exchange",ze="ecc-write",zr=16;var fi=new Error("Invalid key use. Please use 'encryption' or 'signing"),Vf=new Error("Max must be less than 256 and greater than 0");function Pr(t){return new Uint8Array(t).buffer}x(Pr,"toArrayBuffer");async function oi(t){return new Uint8Array(await k.subtle.digest("sha-256",t.buffer))}x(oi,"sha256");function Dr(t){let e=_r(t,"base64pad");return Pr(e)}x(Dr,"base64ToArrBuf");var ae=x((t,e)=>{if(typeof t=="string")return e(t);if(typeof t=="object"&&t.byteLength!==void 0)return new Uint8Array(t).buffer;throw new Error("Improper value. Must be a string, ArrayBuffer, Uint8Array")},"normalizeToBuf");function yt(t){return ae(t,Dr)}x(yt,"normalizeBase64ToBuf");var Xf=x(t=>ae(t,e=>ai(e,8)),"normalizeUtf8ToBuf");function ai(t,e){let i=e===8?new Uint8Array(t.length):new Uint16Array(t.length);for(let s=0,y=t.length;s<y;s++)i[s]=t.charCodeAt(s);return i.buffer}x(ai,"strToArrBuf");var kf=x(t=>ae(t,e=>ai(e,16)),"normalizeUtf16ToBuf");function re(t,e){switch(e){case 8:return Xf(t);default:return kf(t)}}x(re,"normalizeUnicodeToBuf");function xt(t){if(!t.startsWith(Ae))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=""+t.substring(Ae.length),i=_r(e,"base58btc"),{keyBuffer:s,type:y}=Wf(Pr(i));return{publicKey:new Uint8Array(s),type:y}}x(xt,"didToPublicKey");function Wf(t){if(sn(t,Pr(it)))return{keyBuffer:t.slice(it.byteLength),type:Ne.RSA};if(sn(t,Pr(at)))return{keyBuffer:t.slice(at.byteLength),type:Ne.Edwards};if(sn(t,Pr(ot)))return{keyBuffer:t.slice(ot.byteLength),type:Ne.BLS};throw new Error("Unsupported key algorithm. Try using RSA.")}x(Wf,"parseMagicBytes");var $f={equal:x((t,e)=>{let i=new Uint8Array(t),s=new Uint8Array(e);if(i.length!==s.length)return!1;for(let y=0;y<i.length;y++)if(i[y]!==s[y])return!1;return!0},"equal")};function sn(t,e){return $f.equal(e,t.slice(0,e.byteLength))}x(sn,"hasPrefix");function Ur(t){return nr(t instanceof ArrayBuffer?new Uint8Array(t):t,"base64pad")}x(Ur,"toBase64");async function Oe(t,e){let i=typeof t=="string"?Dr(t):Pr(t);return k.subtle.importKey("raw",i,{name:e?.alg||jr,length:e?.length||Fr},!0,["encrypt","decrypt"])}x(Oe,"importKey");function ut(t,{max:e}={max:255}){if(e<1||e>255)throw Vf;let i=new Uint8Array(t);if(e===255)return k.getRandomValues(i),i.buffer;let s=0,y=e+1,g=Math.floor(256/y)*y,E=new Uint8Array(1);for(;s<i.length;)k.getRandomValues(E),E[0]<g&&(i[s]=E[0]%y,s++);return i.buffer}x(ut,"randomBuf");function kr(t,e){let i=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(Pr(t)),s=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(Pr(e)),y=new Uint8Array(i.length+s.length);return y.set(i),y.set(s,i.length),y.buffer}x(kr,"joinBufs");async function cn(t,e,i,s){let y=s||!1;if(!Object.values(ie).includes(i))throw new Error("invalid key use");let g=i==="exchange"?Jr:Qr,E=i==="exchange"?["encrypt","decrypt"]:["sign","verify"];return k.subtle.generateKey({name:g,modulusLength:t,publicExponent:Zf(),hash:{name:e}},y,E)}x(cn,"makeRSAKeypair");function Zf(){return new Uint8Array([1,0,1])}x(Zf,"publicExponent");var xi=Ii(ci(),1);async function qf({message:t,publicKey:e,signature:i}){return xi.default.sign.detached.verify(t,i,e)}x(qf,"ed25519Verify");var yi={keyTypes:{"bls12-381":{magicBytes:new Uint8Array([234,1]),verify:x(()=>{throw new Error("Not implemented")},"verify")},rsa:{magicBytes:new Uint8Array([0,245,2]),verify:Jf},ed25519:{magicBytes:new Uint8Array([237,1]),verify:qf}}};async function Jf({message:t,publicKey:e,signature:i}){return Wr.verify(t,i,await k.subtle.importKey("spki",Pr(e),{name:Qr,hash:nt},!1,["verify"]),8)}x(Jf,"rsaVerify");var Wr={verify:x(async function(e,i,s,y=Yr,g=oe){return k.subtle.verify({name:Qr,saltLength:zr},typeof s=="string"?await Ye(s,g,"signing"):s,yt(i),re(e,y))},"rsaVerify"),sign:x(async function(e,i,s=Yr){return k.subtle.sign({name:Qr,saltLength:zr},i,re(e,s))},"sign"),encrypt:x(async function(e,i,s=Yr,y=oe){let g;return typeof i=="string"?g=await Ye(i,y,"exchange"):g=i instanceof Uint8Array?await Ye(Pr(i),y,"exchange"):i,k.subtle.encrypt({name:Jr},g,re(e,s))},"rsaEncrypt"),decrypt:x(async function(e,i){let s=we(i)?i:await to(i,["decrypt"]),y;typeof e=="string"?y=_r(e,"base64pad"):y=e;let g=await k.subtle.decrypt({name:Jr},s,y instanceof Uint8Array?Pr(y):y);return new Uint8Array(g)},"rsaDecrypt")};async function Ye(t,e,i){Qf(i);let s=i==="exchange"?Jr:Qr,y=i==="exchange"?["encrypt"]:["verify"],g=typeof t=="string"?Dr(eo(t)):t;return k.subtle.importKey("spki",g,{name:s,hash:{name:e}},!0,y)}x(Ye,"importPublicKey");function Qf(t){ro(t,["signing","exchange"],fi)}x(Qf,"checkValidKeyUse");function ro(t,e,i){if(!e.some(y=>y===t))throw i}x(ro,"checkValid");function eo(t){return t.replace(`-----BEGIN PUBLIC KEY-----
|
|
1
|
+
"use strict";(()=>{var Bi=Object.create;var rt=Object.defineProperty;var Ti=Object.getOwnPropertyDescriptor;var Di=Object.getOwnPropertyNames;var Ii=Object.getPrototypeOf,Mi=Object.prototype.hasOwnProperty;var x=(t,e)=>rt(t,"name",{value:e,configurable:!0}),Mn=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,i)=>(typeof require<"u"?require:e)[i]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Ln=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Ur=(t,e)=>{for(var i in e)rt(t,i,{get:e[i],enumerable:!0})},Li=(t,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of Di(e))!Mi.call(t,c)&&c!==i&&rt(t,c,{get:()=>e[c],enumerable:!(s=Ti(e,c))||s.enumerable});return t};var Ni=(t,e,i)=>(i=t!=null?Bi(Ii(t)):{},Li(e||!t||!t.__esModule?rt(i,"default",{value:t,enumerable:!0}):i,t));var yi=Ln(()=>{});var xi=Ln((ps,ht)=>{(function(t){"use strict";var e=x(function(n){var o,f=new Float64Array(16);if(n)for(o=0;o<n.length;o++)f[o]=n[o];return f},"gf"),i=x(function(){throw new Error("no PRNG")},"randombytes"),s=new Uint8Array(16),c=new Uint8Array(32);c[0]=9;var d=e(),E=e([1]),M=e([56129,1]),er=e([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),fr=e([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),ir=e([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),br=e([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),Ir=e([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function ye(n,o,f,r){n[o]=f>>24&255,n[o+1]=f>>16&255,n[o+2]=f>>8&255,n[o+3]=f&255,n[o+4]=r>>24&255,n[o+5]=r>>16&255,n[o+6]=r>>8&255,n[o+7]=r&255}x(ye,"ts64");function $(n,o,f,r,a){var u,p=0;for(u=0;u<a;u++)p|=n[o+u]^f[r+u];return(1&p-1>>>8)-1}x($,"vn");function yr(n,o,f,r){return $(n,o,f,r,16)}x(yr,"crypto_verify_16");function vr(n,o,f,r){return $(n,o,f,r,32)}x(vr,"crypto_verify_32");function Kr(n,o,f,r){for(var a=r[0]&255|(r[1]&255)<<8|(r[2]&255)<<16|(r[3]&255)<<24,u=f[0]&255|(f[1]&255)<<8|(f[2]&255)<<16|(f[3]&255)<<24,p=f[4]&255|(f[5]&255)<<8|(f[6]&255)<<16|(f[7]&255)<<24,b=f[8]&255|(f[9]&255)<<8|(f[10]&255)<<16|(f[11]&255)<<24,K=f[12]&255|(f[13]&255)<<8|(f[14]&255)<<16|(f[15]&255)<<24,T=r[4]&255|(r[5]&255)<<8|(r[6]&255)<<16|(r[7]&255)<<24,S=o[0]&255|(o[1]&255)<<8|(o[2]&255)<<16|(o[3]&255)<<24,J=o[4]&255|(o[5]&255)<<8|(o[6]&255)<<16|(o[7]&255)<<24,_=o[8]&255|(o[9]&255)<<8|(o[10]&255)<<16|(o[11]&255)<<24,L=o[12]&255|(o[13]&255)<<8|(o[14]&255)<<16|(o[15]&255)<<24,N=r[8]&255|(r[9]&255)<<8|(r[10]&255)<<16|(r[11]&255)<<24,H=f[16]&255|(f[17]&255)<<8|(f[18]&255)<<16|(f[19]&255)<<24,Y=f[20]&255|(f[21]&255)<<8|(f[22]&255)<<16|(f[23]&255)<<24,R=f[24]&255|(f[25]&255)<<8|(f[26]&255)<<16|(f[27]&255)<<24,O=f[28]&255|(f[29]&255)<<8|(f[30]&255)<<16|(f[31]&255)<<24,z=r[12]&255|(r[13]&255)<<8|(r[14]&255)<<16|(r[15]&255)<<24,C=a,D=u,v=p,P=b,B=K,U=T,h=S,g=J,m=_,l=L,A=N,w=H,I=Y,j=R,G=O,F=z,y,V=0;V<20;V+=2)y=C+I|0,B^=y<<7|y>>>25,y=B+C|0,m^=y<<9|y>>>23,y=m+B|0,I^=y<<13|y>>>19,y=I+m|0,C^=y<<18|y>>>14,y=U+D|0,l^=y<<7|y>>>25,y=l+U|0,j^=y<<9|y>>>23,y=j+l|0,D^=y<<13|y>>>19,y=D+j|0,U^=y<<18|y>>>14,y=A+h|0,G^=y<<7|y>>>25,y=G+A|0,v^=y<<9|y>>>23,y=v+G|0,h^=y<<13|y>>>19,y=h+v|0,A^=y<<18|y>>>14,y=F+w|0,P^=y<<7|y>>>25,y=P+F|0,g^=y<<9|y>>>23,y=g+P|0,w^=y<<13|y>>>19,y=w+g|0,F^=y<<18|y>>>14,y=C+P|0,D^=y<<7|y>>>25,y=D+C|0,v^=y<<9|y>>>23,y=v+D|0,P^=y<<13|y>>>19,y=P+v|0,C^=y<<18|y>>>14,y=U+B|0,h^=y<<7|y>>>25,y=h+U|0,g^=y<<9|y>>>23,y=g+h|0,B^=y<<13|y>>>19,y=B+g|0,U^=y<<18|y>>>14,y=A+l|0,w^=y<<7|y>>>25,y=w+A|0,m^=y<<9|y>>>23,y=m+w|0,l^=y<<13|y>>>19,y=l+m|0,A^=y<<18|y>>>14,y=F+G|0,I^=y<<7|y>>>25,y=I+F|0,j^=y<<9|y>>>23,y=j+I|0,G^=y<<13|y>>>19,y=G+j|0,F^=y<<18|y>>>14;C=C+a|0,D=D+u|0,v=v+p|0,P=P+b|0,B=B+K|0,U=U+T|0,h=h+S|0,g=g+J|0,m=m+_|0,l=l+L|0,A=A+N|0,w=w+H|0,I=I+Y|0,j=j+R|0,G=G+O|0,F=F+z|0,n[0]=C>>>0&255,n[1]=C>>>8&255,n[2]=C>>>16&255,n[3]=C>>>24&255,n[4]=D>>>0&255,n[5]=D>>>8&255,n[6]=D>>>16&255,n[7]=D>>>24&255,n[8]=v>>>0&255,n[9]=v>>>8&255,n[10]=v>>>16&255,n[11]=v>>>24&255,n[12]=P>>>0&255,n[13]=P>>>8&255,n[14]=P>>>16&255,n[15]=P>>>24&255,n[16]=B>>>0&255,n[17]=B>>>8&255,n[18]=B>>>16&255,n[19]=B>>>24&255,n[20]=U>>>0&255,n[21]=U>>>8&255,n[22]=U>>>16&255,n[23]=U>>>24&255,n[24]=h>>>0&255,n[25]=h>>>8&255,n[26]=h>>>16&255,n[27]=h>>>24&255,n[28]=g>>>0&255,n[29]=g>>>8&255,n[30]=g>>>16&255,n[31]=g>>>24&255,n[32]=m>>>0&255,n[33]=m>>>8&255,n[34]=m>>>16&255,n[35]=m>>>24&255,n[36]=l>>>0&255,n[37]=l>>>8&255,n[38]=l>>>16&255,n[39]=l>>>24&255,n[40]=A>>>0&255,n[41]=A>>>8&255,n[42]=A>>>16&255,n[43]=A>>>24&255,n[44]=w>>>0&255,n[45]=w>>>8&255,n[46]=w>>>16&255,n[47]=w>>>24&255,n[48]=I>>>0&255,n[49]=I>>>8&255,n[50]=I>>>16&255,n[51]=I>>>24&255,n[52]=j>>>0&255,n[53]=j>>>8&255,n[54]=j>>>16&255,n[55]=j>>>24&255,n[56]=G>>>0&255,n[57]=G>>>8&255,n[58]=G>>>16&255,n[59]=G>>>24&255,n[60]=F>>>0&255,n[61]=F>>>8&255,n[62]=F>>>16&255,n[63]=F>>>24&255}x(Kr,"core_salsa20");function gr(n,o,f,r){for(var a=r[0]&255|(r[1]&255)<<8|(r[2]&255)<<16|(r[3]&255)<<24,u=f[0]&255|(f[1]&255)<<8|(f[2]&255)<<16|(f[3]&255)<<24,p=f[4]&255|(f[5]&255)<<8|(f[6]&255)<<16|(f[7]&255)<<24,b=f[8]&255|(f[9]&255)<<8|(f[10]&255)<<16|(f[11]&255)<<24,K=f[12]&255|(f[13]&255)<<8|(f[14]&255)<<16|(f[15]&255)<<24,T=r[4]&255|(r[5]&255)<<8|(r[6]&255)<<16|(r[7]&255)<<24,S=o[0]&255|(o[1]&255)<<8|(o[2]&255)<<16|(o[3]&255)<<24,J=o[4]&255|(o[5]&255)<<8|(o[6]&255)<<16|(o[7]&255)<<24,_=o[8]&255|(o[9]&255)<<8|(o[10]&255)<<16|(o[11]&255)<<24,L=o[12]&255|(o[13]&255)<<8|(o[14]&255)<<16|(o[15]&255)<<24,N=r[8]&255|(r[9]&255)<<8|(r[10]&255)<<16|(r[11]&255)<<24,H=f[16]&255|(f[17]&255)<<8|(f[18]&255)<<16|(f[19]&255)<<24,Y=f[20]&255|(f[21]&255)<<8|(f[22]&255)<<16|(f[23]&255)<<24,R=f[24]&255|(f[25]&255)<<8|(f[26]&255)<<16|(f[27]&255)<<24,O=f[28]&255|(f[29]&255)<<8|(f[30]&255)<<16|(f[31]&255)<<24,z=r[12]&255|(r[13]&255)<<8|(r[14]&255)<<16|(r[15]&255)<<24,C=a,D=u,v=p,P=b,B=K,U=T,h=S,g=J,m=_,l=L,A=N,w=H,I=Y,j=R,G=O,F=z,y,V=0;V<20;V+=2)y=C+I|0,B^=y<<7|y>>>25,y=B+C|0,m^=y<<9|y>>>23,y=m+B|0,I^=y<<13|y>>>19,y=I+m|0,C^=y<<18|y>>>14,y=U+D|0,l^=y<<7|y>>>25,y=l+U|0,j^=y<<9|y>>>23,y=j+l|0,D^=y<<13|y>>>19,y=D+j|0,U^=y<<18|y>>>14,y=A+h|0,G^=y<<7|y>>>25,y=G+A|0,v^=y<<9|y>>>23,y=v+G|0,h^=y<<13|y>>>19,y=h+v|0,A^=y<<18|y>>>14,y=F+w|0,P^=y<<7|y>>>25,y=P+F|0,g^=y<<9|y>>>23,y=g+P|0,w^=y<<13|y>>>19,y=w+g|0,F^=y<<18|y>>>14,y=C+P|0,D^=y<<7|y>>>25,y=D+C|0,v^=y<<9|y>>>23,y=v+D|0,P^=y<<13|y>>>19,y=P+v|0,C^=y<<18|y>>>14,y=U+B|0,h^=y<<7|y>>>25,y=h+U|0,g^=y<<9|y>>>23,y=g+h|0,B^=y<<13|y>>>19,y=B+g|0,U^=y<<18|y>>>14,y=A+l|0,w^=y<<7|y>>>25,y=w+A|0,m^=y<<9|y>>>23,y=m+w|0,l^=y<<13|y>>>19,y=l+m|0,A^=y<<18|y>>>14,y=F+G|0,I^=y<<7|y>>>25,y=I+F|0,j^=y<<9|y>>>23,y=j+I|0,G^=y<<13|y>>>19,y=G+j|0,F^=y<<18|y>>>14;n[0]=C>>>0&255,n[1]=C>>>8&255,n[2]=C>>>16&255,n[3]=C>>>24&255,n[4]=U>>>0&255,n[5]=U>>>8&255,n[6]=U>>>16&255,n[7]=U>>>24&255,n[8]=A>>>0&255,n[9]=A>>>8&255,n[10]=A>>>16&255,n[11]=A>>>24&255,n[12]=F>>>0&255,n[13]=F>>>8&255,n[14]=F>>>16&255,n[15]=F>>>24&255,n[16]=h>>>0&255,n[17]=h>>>8&255,n[18]=h>>>16&255,n[19]=h>>>24&255,n[20]=g>>>0&255,n[21]=g>>>8&255,n[22]=g>>>16&255,n[23]=g>>>24&255,n[24]=m>>>0&255,n[25]=m>>>8&255,n[26]=m>>>16&255,n[27]=m>>>24&255,n[28]=l>>>0&255,n[29]=l>>>8&255,n[30]=l>>>16&255,n[31]=l>>>24&255}x(gr,"core_hsalsa20");function Er(n,o,f,r){Kr(n,o,f,r)}x(Er,"crypto_core_salsa20");function dr(n,o,f,r){gr(n,o,f,r)}x(dr,"crypto_core_hsalsa20");var hr=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function Mr(n,o,f,r,a,u,p){var b=new Uint8Array(16),K=new Uint8Array(64),T,S;for(S=0;S<16;S++)b[S]=0;for(S=0;S<8;S++)b[S]=u[S];for(;a>=64;){for(Er(K,b,p,hr),S=0;S<64;S++)n[o+S]=f[r+S]^K[S];for(T=1,S=8;S<16;S++)T=T+(b[S]&255)|0,b[S]=T&255,T>>>=8;a-=64,o+=64,r+=64}if(a>0)for(Er(K,b,p,hr),S=0;S<a;S++)n[o+S]=f[r+S]^K[S];return 0}x(Mr,"crypto_stream_salsa20_xor");function _r(n,o,f,r,a){var u=new Uint8Array(16),p=new Uint8Array(64),b,K;for(K=0;K<16;K++)u[K]=0;for(K=0;K<8;K++)u[K]=r[K];for(;f>=64;){for(Er(p,u,a,hr),K=0;K<64;K++)n[o+K]=p[K];for(b=1,K=8;K<16;K++)b=b+(u[K]&255)|0,u[K]=b&255,b>>>=8;f-=64,o+=64}if(f>0)for(Er(p,u,a,hr),K=0;K<f;K++)n[o+K]=p[K];return 0}x(_r,"crypto_stream_salsa20");function Br(n,o,f,r,a){var u=new Uint8Array(32);dr(u,r,a,hr);for(var p=new Uint8Array(8),b=0;b<8;b++)p[b]=r[b+16];return _r(n,o,f,p,u)}x(Br,"crypto_stream");function Zr(n,o,f,r,a,u,p){var b=new Uint8Array(32);dr(b,u,p,hr);for(var K=new Uint8Array(8),T=0;T<8;T++)K[T]=u[T+16];return Mr(n,o,f,r,a,K,b)}x(Zr,"crypto_stream_xor");var ke=x(function(n){this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.leftover=0,this.fin=0;var o,f,r,a,u,p,b,K;o=n[0]&255|(n[1]&255)<<8,this.r[0]=o&8191,f=n[2]&255|(n[3]&255)<<8,this.r[1]=(o>>>13|f<<3)&8191,r=n[4]&255|(n[5]&255)<<8,this.r[2]=(f>>>10|r<<6)&7939,a=n[6]&255|(n[7]&255)<<8,this.r[3]=(r>>>7|a<<9)&8191,u=n[8]&255|(n[9]&255)<<8,this.r[4]=(a>>>4|u<<12)&255,this.r[5]=u>>>1&8190,p=n[10]&255|(n[11]&255)<<8,this.r[6]=(u>>>14|p<<2)&8191,b=n[12]&255|(n[13]&255)<<8,this.r[7]=(p>>>11|b<<5)&8065,K=n[14]&255|(n[15]&255)<<8,this.r[8]=(b>>>8|K<<8)&8191,this.r[9]=K>>>5&127,this.pad[0]=n[16]&255|(n[17]&255)<<8,this.pad[1]=n[18]&255|(n[19]&255)<<8,this.pad[2]=n[20]&255|(n[21]&255)<<8,this.pad[3]=n[22]&255|(n[23]&255)<<8,this.pad[4]=n[24]&255|(n[25]&255)<<8,this.pad[5]=n[26]&255|(n[27]&255)<<8,this.pad[6]=n[28]&255|(n[29]&255)<<8,this.pad[7]=n[30]&255|(n[31]&255)<<8},"poly1305");ke.prototype.blocks=function(n,o,f){for(var r=this.fin?0:2048,a,u,p,b,K,T,S,J,_,L,N,H,Y,R,O,z,C,D,v,P=this.h[0],B=this.h[1],U=this.h[2],h=this.h[3],g=this.h[4],m=this.h[5],l=this.h[6],A=this.h[7],w=this.h[8],I=this.h[9],j=this.r[0],G=this.r[1],F=this.r[2],y=this.r[3],V=this.r[4],Q=this.r[5],rr=this.r[6],k=this.r[7],Z=this.r[8],q=this.r[9];f>=16;)a=n[o+0]&255|(n[o+1]&255)<<8,P+=a&8191,u=n[o+2]&255|(n[o+3]&255)<<8,B+=(a>>>13|u<<3)&8191,p=n[o+4]&255|(n[o+5]&255)<<8,U+=(u>>>10|p<<6)&8191,b=n[o+6]&255|(n[o+7]&255)<<8,h+=(p>>>7|b<<9)&8191,K=n[o+8]&255|(n[o+9]&255)<<8,g+=(b>>>4|K<<12)&8191,m+=K>>>1&8191,T=n[o+10]&255|(n[o+11]&255)<<8,l+=(K>>>14|T<<2)&8191,S=n[o+12]&255|(n[o+13]&255)<<8,A+=(T>>>11|S<<5)&8191,J=n[o+14]&255|(n[o+15]&255)<<8,w+=(S>>>8|J<<8)&8191,I+=J>>>5|r,_=0,L=_,L+=P*j,L+=B*(5*q),L+=U*(5*Z),L+=h*(5*k),L+=g*(5*rr),_=L>>>13,L&=8191,L+=m*(5*Q),L+=l*(5*V),L+=A*(5*y),L+=w*(5*F),L+=I*(5*G),_+=L>>>13,L&=8191,N=_,N+=P*G,N+=B*j,N+=U*(5*q),N+=h*(5*Z),N+=g*(5*k),_=N>>>13,N&=8191,N+=m*(5*rr),N+=l*(5*Q),N+=A*(5*V),N+=w*(5*y),N+=I*(5*F),_+=N>>>13,N&=8191,H=_,H+=P*F,H+=B*G,H+=U*j,H+=h*(5*q),H+=g*(5*Z),_=H>>>13,H&=8191,H+=m*(5*k),H+=l*(5*rr),H+=A*(5*Q),H+=w*(5*V),H+=I*(5*y),_+=H>>>13,H&=8191,Y=_,Y+=P*y,Y+=B*F,Y+=U*G,Y+=h*j,Y+=g*(5*q),_=Y>>>13,Y&=8191,Y+=m*(5*Z),Y+=l*(5*k),Y+=A*(5*rr),Y+=w*(5*Q),Y+=I*(5*V),_+=Y>>>13,Y&=8191,R=_,R+=P*V,R+=B*y,R+=U*F,R+=h*G,R+=g*j,_=R>>>13,R&=8191,R+=m*(5*q),R+=l*(5*Z),R+=A*(5*k),R+=w*(5*rr),R+=I*(5*Q),_+=R>>>13,R&=8191,O=_,O+=P*Q,O+=B*V,O+=U*y,O+=h*F,O+=g*G,_=O>>>13,O&=8191,O+=m*j,O+=l*(5*q),O+=A*(5*Z),O+=w*(5*k),O+=I*(5*rr),_+=O>>>13,O&=8191,z=_,z+=P*rr,z+=B*Q,z+=U*V,z+=h*y,z+=g*F,_=z>>>13,z&=8191,z+=m*G,z+=l*j,z+=A*(5*q),z+=w*(5*Z),z+=I*(5*k),_+=z>>>13,z&=8191,C=_,C+=P*k,C+=B*rr,C+=U*Q,C+=h*V,C+=g*y,_=C>>>13,C&=8191,C+=m*F,C+=l*G,C+=A*j,C+=w*(5*q),C+=I*(5*Z),_+=C>>>13,C&=8191,D=_,D+=P*Z,D+=B*k,D+=U*rr,D+=h*Q,D+=g*V,_=D>>>13,D&=8191,D+=m*y,D+=l*F,D+=A*G,D+=w*j,D+=I*(5*q),_+=D>>>13,D&=8191,v=_,v+=P*q,v+=B*Z,v+=U*k,v+=h*rr,v+=g*Q,_=v>>>13,v&=8191,v+=m*V,v+=l*y,v+=A*F,v+=w*G,v+=I*j,_+=v>>>13,v&=8191,_=(_<<2)+_|0,_=_+L|0,L=_&8191,_=_>>>13,N+=_,P=L,B=N,U=H,h=Y,g=R,m=O,l=z,A=C,w=D,I=v,o+=16,f-=16;this.h[0]=P,this.h[1]=B,this.h[2]=U,this.h[3]=h,this.h[4]=g,this.h[5]=m,this.h[6]=l,this.h[7]=A,this.h[8]=w,this.h[9]=I},ke.prototype.finish=function(n,o){var f=new Uint16Array(10),r,a,u,p;if(this.leftover){for(p=this.leftover,this.buffer[p++]=1;p<16;p++)this.buffer[p]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(r=this.h[1]>>>13,this.h[1]&=8191,p=2;p<10;p++)this.h[p]+=r,r=this.h[p]>>>13,this.h[p]&=8191;for(this.h[0]+=r*5,r=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=r,r=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=r,f[0]=this.h[0]+5,r=f[0]>>>13,f[0]&=8191,p=1;p<10;p++)f[p]=this.h[p]+r,r=f[p]>>>13,f[p]&=8191;for(f[9]-=8192,a=(r^1)-1,p=0;p<10;p++)f[p]&=a;for(a=~a,p=0;p<10;p++)this.h[p]=this.h[p]&a|f[p];for(this.h[0]=(this.h[0]|this.h[1]<<13)&65535,this.h[1]=(this.h[1]>>>3|this.h[2]<<10)&65535,this.h[2]=(this.h[2]>>>6|this.h[3]<<7)&65535,this.h[3]=(this.h[3]>>>9|this.h[4]<<4)&65535,this.h[4]=(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14)&65535,this.h[5]=(this.h[6]>>>2|this.h[7]<<11)&65535,this.h[6]=(this.h[7]>>>5|this.h[8]<<8)&65535,this.h[7]=(this.h[8]>>>8|this.h[9]<<5)&65535,u=this.h[0]+this.pad[0],this.h[0]=u&65535,p=1;p<8;p++)u=(this.h[p]+this.pad[p]|0)+(u>>>16)|0,this.h[p]=u&65535;n[o+0]=this.h[0]>>>0&255,n[o+1]=this.h[0]>>>8&255,n[o+2]=this.h[1]>>>0&255,n[o+3]=this.h[1]>>>8&255,n[o+4]=this.h[2]>>>0&255,n[o+5]=this.h[2]>>>8&255,n[o+6]=this.h[3]>>>0&255,n[o+7]=this.h[3]>>>8&255,n[o+8]=this.h[4]>>>0&255,n[o+9]=this.h[4]>>>8&255,n[o+10]=this.h[5]>>>0&255,n[o+11]=this.h[5]>>>8&255,n[o+12]=this.h[6]>>>0&255,n[o+13]=this.h[6]>>>8&255,n[o+14]=this.h[7]>>>0&255,n[o+15]=this.h[7]>>>8&255},ke.prototype.update=function(n,o,f){var r,a;if(this.leftover){for(a=16-this.leftover,a>f&&(a=f),r=0;r<a;r++)this.buffer[this.leftover+r]=n[o+r];if(f-=a,o+=a,this.leftover+=a,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(f>=16&&(a=f-f%16,this.blocks(n,o,a),o+=a,f-=a),f){for(r=0;r<f;r++)this.buffer[this.leftover+r]=n[o+r];this.leftover+=f}};function At(n,o,f,r,a,u){var p=new ke(u);return p.update(f,r,a),p.finish(n,o),0}x(At,"crypto_onetimeauth");function mn(n,o,f,r,a,u){var p=new Uint8Array(16);return At(p,0,f,r,a,u),yr(n,o,p,0)}x(mn,"crypto_onetimeauth_verify");function mt(n,o,f,r,a){var u;if(f<32)return-1;for(Zr(n,0,o,0,f,r,a),At(n,16,n,32,f-32,n),u=0;u<16;u++)n[u]=0;return 0}x(mt,"crypto_secretbox");function wt(n,o,f,r,a){var u,p=new Uint8Array(32);if(f<32||(Br(p,0,32,r,a),mn(o,16,o,32,f-32,p)!==0))return-1;for(Zr(n,0,o,0,f,r,a),u=0;u<32;u++)n[u]=0;return 0}x(wt,"crypto_secretbox_open");function Gr(n,o){var f;for(f=0;f<16;f++)n[f]=o[f]|0}x(Gr,"set25519");function Kt(n){var o,f,r=1;for(o=0;o<16;o++)f=n[o]+r+65535,r=Math.floor(f/65536),n[o]=f-r*65536;n[0]+=r-1+37*(r-1)}x(Kt,"car25519");function xe(n,o,f){for(var r,a=~(f-1),u=0;u<16;u++)r=a&(n[u]^o[u]),n[u]^=r,o[u]^=r}x(xe,"sel25519");function ue(n,o){var f,r,a,u=e(),p=e();for(f=0;f<16;f++)p[f]=o[f];for(Kt(p),Kt(p),Kt(p),r=0;r<2;r++){for(u[0]=p[0]-65517,f=1;f<15;f++)u[f]=p[f]-65535-(u[f-1]>>16&1),u[f-1]&=65535;u[15]=p[15]-32767-(u[14]>>16&1),a=u[15]>>16&1,u[14]&=65535,xe(p,u,1-a)}for(f=0;f<16;f++)n[2*f]=p[f]&255,n[2*f+1]=p[f]>>8}x(ue,"pack25519");function wn(n,o){var f=new Uint8Array(32),r=new Uint8Array(32);return ue(f,n),ue(r,o),vr(f,0,r,0)}x(wn,"neq25519");function Kn(n){var o=new Uint8Array(32);return ue(o,n),o[0]&1}x(Kn,"par25519");function Et(n,o){var f;for(f=0;f<16;f++)n[f]=o[2*f]+(o[2*f+1]<<8);n[15]&=32767}x(Et,"unpack25519");function Lr(n,o,f){for(var r=0;r<16;r++)n[r]=o[r]+f[r]}x(Lr,"A");function Nr(n,o,f){for(var r=0;r<16;r++)n[r]=o[r]-f[r]}x(Nr,"Z");function W(n,o,f){var r,a,u=0,p=0,b=0,K=0,T=0,S=0,J=0,_=0,L=0,N=0,H=0,Y=0,R=0,O=0,z=0,C=0,D=0,v=0,P=0,B=0,U=0,h=0,g=0,m=0,l=0,A=0,w=0,I=0,j=0,G=0,F=0,y=f[0],V=f[1],Q=f[2],rr=f[3],k=f[4],Z=f[5],q=f[6],xr=f[7],tr=f[8],or=f[9],ar=f[10],sr=f[11],pr=f[12],Ar=f[13],mr=f[14],wr=f[15];r=o[0],u+=r*y,p+=r*V,b+=r*Q,K+=r*rr,T+=r*k,S+=r*Z,J+=r*q,_+=r*xr,L+=r*tr,N+=r*or,H+=r*ar,Y+=r*sr,R+=r*pr,O+=r*Ar,z+=r*mr,C+=r*wr,r=o[1],p+=r*y,b+=r*V,K+=r*Q,T+=r*rr,S+=r*k,J+=r*Z,_+=r*q,L+=r*xr,N+=r*tr,H+=r*or,Y+=r*ar,R+=r*sr,O+=r*pr,z+=r*Ar,C+=r*mr,D+=r*wr,r=o[2],b+=r*y,K+=r*V,T+=r*Q,S+=r*rr,J+=r*k,_+=r*Z,L+=r*q,N+=r*xr,H+=r*tr,Y+=r*or,R+=r*ar,O+=r*sr,z+=r*pr,C+=r*Ar,D+=r*mr,v+=r*wr,r=o[3],K+=r*y,T+=r*V,S+=r*Q,J+=r*rr,_+=r*k,L+=r*Z,N+=r*q,H+=r*xr,Y+=r*tr,R+=r*or,O+=r*ar,z+=r*sr,C+=r*pr,D+=r*Ar,v+=r*mr,P+=r*wr,r=o[4],T+=r*y,S+=r*V,J+=r*Q,_+=r*rr,L+=r*k,N+=r*Z,H+=r*q,Y+=r*xr,R+=r*tr,O+=r*or,z+=r*ar,C+=r*sr,D+=r*pr,v+=r*Ar,P+=r*mr,B+=r*wr,r=o[5],S+=r*y,J+=r*V,_+=r*Q,L+=r*rr,N+=r*k,H+=r*Z,Y+=r*q,R+=r*xr,O+=r*tr,z+=r*or,C+=r*ar,D+=r*sr,v+=r*pr,P+=r*Ar,B+=r*mr,U+=r*wr,r=o[6],J+=r*y,_+=r*V,L+=r*Q,N+=r*rr,H+=r*k,Y+=r*Z,R+=r*q,O+=r*xr,z+=r*tr,C+=r*or,D+=r*ar,v+=r*sr,P+=r*pr,B+=r*Ar,U+=r*mr,h+=r*wr,r=o[7],_+=r*y,L+=r*V,N+=r*Q,H+=r*rr,Y+=r*k,R+=r*Z,O+=r*q,z+=r*xr,C+=r*tr,D+=r*or,v+=r*ar,P+=r*sr,B+=r*pr,U+=r*Ar,h+=r*mr,g+=r*wr,r=o[8],L+=r*y,N+=r*V,H+=r*Q,Y+=r*rr,R+=r*k,O+=r*Z,z+=r*q,C+=r*xr,D+=r*tr,v+=r*or,P+=r*ar,B+=r*sr,U+=r*pr,h+=r*Ar,g+=r*mr,m+=r*wr,r=o[9],N+=r*y,H+=r*V,Y+=r*Q,R+=r*rr,O+=r*k,z+=r*Z,C+=r*q,D+=r*xr,v+=r*tr,P+=r*or,B+=r*ar,U+=r*sr,h+=r*pr,g+=r*Ar,m+=r*mr,l+=r*wr,r=o[10],H+=r*y,Y+=r*V,R+=r*Q,O+=r*rr,z+=r*k,C+=r*Z,D+=r*q,v+=r*xr,P+=r*tr,B+=r*or,U+=r*ar,h+=r*sr,g+=r*pr,m+=r*Ar,l+=r*mr,A+=r*wr,r=o[11],Y+=r*y,R+=r*V,O+=r*Q,z+=r*rr,C+=r*k,D+=r*Z,v+=r*q,P+=r*xr,B+=r*tr,U+=r*or,h+=r*ar,g+=r*sr,m+=r*pr,l+=r*Ar,A+=r*mr,w+=r*wr,r=o[12],R+=r*y,O+=r*V,z+=r*Q,C+=r*rr,D+=r*k,v+=r*Z,P+=r*q,B+=r*xr,U+=r*tr,h+=r*or,g+=r*ar,m+=r*sr,l+=r*pr,A+=r*Ar,w+=r*mr,I+=r*wr,r=o[13],O+=r*y,z+=r*V,C+=r*Q,D+=r*rr,v+=r*k,P+=r*Z,B+=r*q,U+=r*xr,h+=r*tr,g+=r*or,m+=r*ar,l+=r*sr,A+=r*pr,w+=r*Ar,I+=r*mr,j+=r*wr,r=o[14],z+=r*y,C+=r*V,D+=r*Q,v+=r*rr,P+=r*k,B+=r*Z,U+=r*q,h+=r*xr,g+=r*tr,m+=r*or,l+=r*ar,A+=r*sr,w+=r*pr,I+=r*Ar,j+=r*mr,G+=r*wr,r=o[15],C+=r*y,D+=r*V,v+=r*Q,P+=r*rr,B+=r*k,U+=r*Z,h+=r*q,g+=r*xr,m+=r*tr,l+=r*or,A+=r*ar,w+=r*sr,I+=r*pr,j+=r*Ar,G+=r*mr,F+=r*wr,u+=38*D,p+=38*v,b+=38*P,K+=38*B,T+=38*U,S+=38*h,J+=38*g,_+=38*m,L+=38*l,N+=38*A,H+=38*w,Y+=38*I,R+=38*j,O+=38*G,z+=38*F,a=1,r=u+a+65535,a=Math.floor(r/65536),u=r-a*65536,r=p+a+65535,a=Math.floor(r/65536),p=r-a*65536,r=b+a+65535,a=Math.floor(r/65536),b=r-a*65536,r=K+a+65535,a=Math.floor(r/65536),K=r-a*65536,r=T+a+65535,a=Math.floor(r/65536),T=r-a*65536,r=S+a+65535,a=Math.floor(r/65536),S=r-a*65536,r=J+a+65535,a=Math.floor(r/65536),J=r-a*65536,r=_+a+65535,a=Math.floor(r/65536),_=r-a*65536,r=L+a+65535,a=Math.floor(r/65536),L=r-a*65536,r=N+a+65535,a=Math.floor(r/65536),N=r-a*65536,r=H+a+65535,a=Math.floor(r/65536),H=r-a*65536,r=Y+a+65535,a=Math.floor(r/65536),Y=r-a*65536,r=R+a+65535,a=Math.floor(r/65536),R=r-a*65536,r=O+a+65535,a=Math.floor(r/65536),O=r-a*65536,r=z+a+65535,a=Math.floor(r/65536),z=r-a*65536,r=C+a+65535,a=Math.floor(r/65536),C=r-a*65536,u+=a-1+37*(a-1),a=1,r=u+a+65535,a=Math.floor(r/65536),u=r-a*65536,r=p+a+65535,a=Math.floor(r/65536),p=r-a*65536,r=b+a+65535,a=Math.floor(r/65536),b=r-a*65536,r=K+a+65535,a=Math.floor(r/65536),K=r-a*65536,r=T+a+65535,a=Math.floor(r/65536),T=r-a*65536,r=S+a+65535,a=Math.floor(r/65536),S=r-a*65536,r=J+a+65535,a=Math.floor(r/65536),J=r-a*65536,r=_+a+65535,a=Math.floor(r/65536),_=r-a*65536,r=L+a+65535,a=Math.floor(r/65536),L=r-a*65536,r=N+a+65535,a=Math.floor(r/65536),N=r-a*65536,r=H+a+65535,a=Math.floor(r/65536),H=r-a*65536,r=Y+a+65535,a=Math.floor(r/65536),Y=r-a*65536,r=R+a+65535,a=Math.floor(r/65536),R=r-a*65536,r=O+a+65535,a=Math.floor(r/65536),O=r-a*65536,r=z+a+65535,a=Math.floor(r/65536),z=r-a*65536,r=C+a+65535,a=Math.floor(r/65536),C=r-a*65536,u+=a-1+37*(a-1),n[0]=u,n[1]=p,n[2]=b,n[3]=K,n[4]=T,n[5]=S,n[6]=J,n[7]=_,n[8]=L,n[9]=N,n[10]=H,n[11]=Y,n[12]=R,n[13]=O,n[14]=z,n[15]=C}x(W,"M");function Tr(n,o){W(n,o,o)}x(Tr,"S");function En(n,o){var f=e(),r;for(r=0;r<16;r++)f[r]=o[r];for(r=253;r>=0;r--)Tr(f,f),r!==2&&r!==4&&W(f,f,o);for(r=0;r<16;r++)n[r]=f[r]}x(En,"inv25519");function Un(n,o){var f=e(),r;for(r=0;r<16;r++)f[r]=o[r];for(r=250;r>=0;r--)Tr(f,f),r!==1&&W(f,f,o);for(r=0;r<16;r++)n[r]=f[r]}x(Un,"pow2523");function Ve(n,o,f){var r=new Uint8Array(32),a=new Float64Array(80),u,p,b=e(),K=e(),T=e(),S=e(),J=e(),_=e();for(p=0;p<31;p++)r[p]=o[p];for(r[31]=o[31]&127|64,r[0]&=248,Et(a,f),p=0;p<16;p++)K[p]=a[p],S[p]=b[p]=T[p]=0;for(b[0]=S[0]=1,p=254;p>=0;--p)u=r[p>>>3]>>>(p&7)&1,xe(b,K,u),xe(T,S,u),Lr(J,b,T),Nr(b,b,T),Lr(T,K,S),Nr(K,K,S),Tr(S,J),Tr(_,b),W(b,T,b),W(T,K,J),Lr(J,b,T),Nr(b,b,T),Tr(K,b),Nr(T,S,_),W(b,T,M),Lr(b,b,S),W(T,T,b),W(b,S,_),W(S,K,a),Tr(K,J),xe(b,K,u),xe(T,S,u);for(p=0;p<16;p++)a[p+16]=b[p],a[p+32]=T[p],a[p+48]=K[p],a[p+64]=S[p];var L=a.subarray(32),N=a.subarray(16);return En(L,L),W(N,N,L),ue(n,N),0}x(Ve,"crypto_scalarmult");function Xe(n,o){return Ve(n,o,c)}x(Xe,"crypto_scalarmult_base");function Sn(n,o){return i(o,32),Xe(n,o)}x(Sn,"crypto_box_keypair");function We(n,o,f){var r=new Uint8Array(32);return Ve(r,f,o),dr(n,s,r,hr)}x(We,"crypto_box_beforenm");var vn=mt,Ei=wt;function Ui(n,o,f,r,a,u){var p=new Uint8Array(32);return We(p,a,u),vn(n,o,f,r,p)}x(Ui,"crypto_box");function Si(n,o,f,r,a,u){var p=new Uint8Array(32);return We(p,a,u),Ei(n,o,f,r,p)}x(Si,"crypto_box_open");var _n=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function Cn(n,o,f,r){for(var a=new Int32Array(16),u=new Int32Array(16),p,b,K,T,S,J,_,L,N,H,Y,R,O,z,C,D,v,P,B,U,h,g,m,l,A,w,I=n[0],j=n[1],G=n[2],F=n[3],y=n[4],V=n[5],Q=n[6],rr=n[7],k=o[0],Z=o[1],q=o[2],xr=o[3],tr=o[4],or=o[5],ar=o[6],sr=o[7],pr=0;r>=128;){for(B=0;B<16;B++)U=8*B+pr,a[B]=f[U+0]<<24|f[U+1]<<16|f[U+2]<<8|f[U+3],u[B]=f[U+4]<<24|f[U+5]<<16|f[U+6]<<8|f[U+7];for(B=0;B<80;B++)if(p=I,b=j,K=G,T=F,S=y,J=V,_=Q,L=rr,N=k,H=Z,Y=q,R=xr,O=tr,z=or,C=ar,D=sr,h=rr,g=sr,m=g&65535,l=g>>>16,A=h&65535,w=h>>>16,h=(y>>>14|tr<<18)^(y>>>18|tr<<14)^(tr>>>9|y<<23),g=(tr>>>14|y<<18)^(tr>>>18|y<<14)^(y>>>9|tr<<23),m+=g&65535,l+=g>>>16,A+=h&65535,w+=h>>>16,h=y&V^~y&Q,g=tr&or^~tr&ar,m+=g&65535,l+=g>>>16,A+=h&65535,w+=h>>>16,h=_n[B*2],g=_n[B*2+1],m+=g&65535,l+=g>>>16,A+=h&65535,w+=h>>>16,h=a[B%16],g=u[B%16],m+=g&65535,l+=g>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,v=A&65535|w<<16,P=m&65535|l<<16,h=v,g=P,m=g&65535,l=g>>>16,A=h&65535,w=h>>>16,h=(I>>>28|k<<4)^(k>>>2|I<<30)^(k>>>7|I<<25),g=(k>>>28|I<<4)^(I>>>2|k<<30)^(I>>>7|k<<25),m+=g&65535,l+=g>>>16,A+=h&65535,w+=h>>>16,h=I&j^I&G^j&G,g=k&Z^k&q^Z&q,m+=g&65535,l+=g>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,L=A&65535|w<<16,D=m&65535|l<<16,h=T,g=R,m=g&65535,l=g>>>16,A=h&65535,w=h>>>16,h=v,g=P,m+=g&65535,l+=g>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,T=A&65535|w<<16,R=m&65535|l<<16,j=p,G=b,F=K,y=T,V=S,Q=J,rr=_,I=L,Z=N,q=H,xr=Y,tr=R,or=O,ar=z,sr=C,k=D,B%16===15)for(U=0;U<16;U++)h=a[U],g=u[U],m=g&65535,l=g>>>16,A=h&65535,w=h>>>16,h=a[(U+9)%16],g=u[(U+9)%16],m+=g&65535,l+=g>>>16,A+=h&65535,w+=h>>>16,v=a[(U+1)%16],P=u[(U+1)%16],h=(v>>>1|P<<31)^(v>>>8|P<<24)^v>>>7,g=(P>>>1|v<<31)^(P>>>8|v<<24)^(P>>>7|v<<25),m+=g&65535,l+=g>>>16,A+=h&65535,w+=h>>>16,v=a[(U+14)%16],P=u[(U+14)%16],h=(v>>>19|P<<13)^(P>>>29|v<<3)^v>>>6,g=(P>>>19|v<<13)^(v>>>29|P<<3)^(P>>>6|v<<26),m+=g&65535,l+=g>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,a[U]=A&65535|w<<16,u[U]=m&65535|l<<16;h=I,g=k,m=g&65535,l=g>>>16,A=h&65535,w=h>>>16,h=n[0],g=o[0],m+=g&65535,l+=g>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,n[0]=I=A&65535|w<<16,o[0]=k=m&65535|l<<16,h=j,g=Z,m=g&65535,l=g>>>16,A=h&65535,w=h>>>16,h=n[1],g=o[1],m+=g&65535,l+=g>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,n[1]=j=A&65535|w<<16,o[1]=Z=m&65535|l<<16,h=G,g=q,m=g&65535,l=g>>>16,A=h&65535,w=h>>>16,h=n[2],g=o[2],m+=g&65535,l+=g>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,n[2]=G=A&65535|w<<16,o[2]=q=m&65535|l<<16,h=F,g=xr,m=g&65535,l=g>>>16,A=h&65535,w=h>>>16,h=n[3],g=o[3],m+=g&65535,l+=g>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,n[3]=F=A&65535|w<<16,o[3]=xr=m&65535|l<<16,h=y,g=tr,m=g&65535,l=g>>>16,A=h&65535,w=h>>>16,h=n[4],g=o[4],m+=g&65535,l+=g>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,n[4]=y=A&65535|w<<16,o[4]=tr=m&65535|l<<16,h=V,g=or,m=g&65535,l=g>>>16,A=h&65535,w=h>>>16,h=n[5],g=o[5],m+=g&65535,l+=g>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,n[5]=V=A&65535|w<<16,o[5]=or=m&65535|l<<16,h=Q,g=ar,m=g&65535,l=g>>>16,A=h&65535,w=h>>>16,h=n[6],g=o[6],m+=g&65535,l+=g>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,n[6]=Q=A&65535|w<<16,o[6]=ar=m&65535|l<<16,h=rr,g=sr,m=g&65535,l=g>>>16,A=h&65535,w=h>>>16,h=n[7],g=o[7],m+=g&65535,l+=g>>>16,A+=h&65535,w+=h>>>16,l+=m>>>16,A+=l>>>16,w+=A>>>16,n[7]=rr=A&65535|w<<16,o[7]=sr=m&65535|l<<16,pr+=128,r-=128}return r}x(Cn,"crypto_hashblocks_hl");function ne(n,o,f){var r=new Int32Array(8),a=new Int32Array(8),u=new Uint8Array(256),p,b=f;for(r[0]=1779033703,r[1]=3144134277,r[2]=1013904242,r[3]=2773480762,r[4]=1359893119,r[5]=2600822924,r[6]=528734635,r[7]=1541459225,a[0]=4089235720,a[1]=2227873595,a[2]=4271175723,a[3]=1595750129,a[4]=2917565137,a[5]=725511199,a[6]=4215389547,a[7]=327033209,Cn(r,a,o,f),f%=128,p=0;p<f;p++)u[p]=o[b-f+p];for(u[f]=128,f=256-128*(f<112?1:0),u[f-9]=0,ye(u,f-8,b/536870912|0,b<<3),Cn(r,a,u,f),p=0;p<8;p++)ye(n,8*p,r[p],a[p]);return 0}x(ne,"crypto_hash");function $e(n,o){var f=e(),r=e(),a=e(),u=e(),p=e(),b=e(),K=e(),T=e(),S=e();Nr(f,n[1],n[0]),Nr(S,o[1],o[0]),W(f,f,S),Lr(r,n[0],n[1]),Lr(S,o[0],o[1]),W(r,r,S),W(a,n[3],o[3]),W(a,a,fr),W(u,n[2],o[2]),Lr(u,u,u),Nr(p,r,f),Nr(b,u,a),Lr(K,u,a),Lr(T,r,f),W(n[0],p,b),W(n[1],T,K),W(n[2],K,b),W(n[3],p,T)}x($e,"add");function Pn(n,o,f){var r;for(r=0;r<4;r++)xe(n[r],o[r],f)}x(Pn,"cswap");function Ut(n,o){var f=e(),r=e(),a=e();En(a,o[2]),W(f,o[0],a),W(r,o[1],a),ue(n,r),n[31]^=Kn(f)<<7}x(Ut,"pack");function St(n,o,f){var r,a;for(Gr(n[0],d),Gr(n[1],E),Gr(n[2],E),Gr(n[3],d),a=255;a>=0;--a)r=f[a/8|0]>>(a&7)&1,Pn(n,o,r),$e(o,n),$e(n,n),Pn(n,o,r)}x(St,"scalarmult");function Ze(n,o){var f=[e(),e(),e(),e()];Gr(f[0],ir),Gr(f[1],br),Gr(f[2],E),W(f[3],ir,br),St(n,f,o)}x(Ze,"scalarbase");function vt(n,o,f){var r=new Uint8Array(64),a=[e(),e(),e(),e()],u;for(f||i(o,32),ne(r,o,32),r[0]&=248,r[31]&=127,r[31]|=64,Ze(a,r),Ut(n,a),u=0;u<32;u++)o[u+32]=n[u];return 0}x(vt,"crypto_sign_keypair");var qe=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function _t(n,o){var f,r,a,u;for(r=63;r>=32;--r){for(f=0,a=r-32,u=r-12;a<u;++a)o[a]+=f-16*o[r]*qe[a-(r-32)],f=Math.floor((o[a]+128)/256),o[a]-=f*256;o[a]+=f,o[r]=0}for(f=0,a=0;a<32;a++)o[a]+=f-(o[31]>>4)*qe[a],f=o[a]>>8,o[a]&=255;for(a=0;a<32;a++)o[a]-=f*qe[a];for(r=0;r<32;r++)o[r+1]+=o[r]>>8,n[r]=o[r]&255}x(_t,"modL");function Ct(n){var o=new Float64Array(64),f;for(f=0;f<64;f++)o[f]=n[f];for(f=0;f<64;f++)n[f]=0;_t(n,o)}x(Ct,"reduce");function Bn(n,o,f,r){var a=new Uint8Array(64),u=new Uint8Array(64),p=new Uint8Array(64),b,K,T=new Float64Array(64),S=[e(),e(),e(),e()];ne(a,r,32),a[0]&=248,a[31]&=127,a[31]|=64;var J=f+64;for(b=0;b<f;b++)n[64+b]=o[b];for(b=0;b<32;b++)n[32+b]=a[32+b];for(ne(p,n.subarray(32),f+32),Ct(p),Ze(S,p),Ut(n,S),b=32;b<64;b++)n[b]=r[b];for(ne(u,n,f+64),Ct(u),b=0;b<64;b++)T[b]=0;for(b=0;b<32;b++)T[b]=p[b];for(b=0;b<32;b++)for(K=0;K<32;K++)T[b+K]+=u[b]*a[K];return _t(n.subarray(32),T),J}x(Bn,"crypto_sign");function vi(n,o){var f=e(),r=e(),a=e(),u=e(),p=e(),b=e(),K=e();return Gr(n[2],E),Et(n[1],o),Tr(a,n[1]),W(u,a,er),Nr(a,a,n[2]),Lr(u,n[2],u),Tr(p,u),Tr(b,p),W(K,b,p),W(f,K,a),W(f,f,u),Un(f,f),W(f,f,a),W(f,f,u),W(f,f,u),W(n[0],f,u),Tr(r,n[0]),W(r,r,u),wn(r,a)&&W(n[0],n[0],Ir),Tr(r,n[0]),W(r,r,u),wn(r,a)?-1:(Kn(n[0])===o[31]>>7&&Nr(n[0],d,n[0]),W(n[3],n[0],n[1]),0)}x(vi,"unpackneg");function Pt(n,o,f,r){var a,u=new Uint8Array(32),p=new Uint8Array(64),b=[e(),e(),e(),e()],K=[e(),e(),e(),e()];if(f<64||vi(K,r))return-1;for(a=0;a<f;a++)n[a]=o[a];for(a=0;a<32;a++)n[a+32]=r[a];if(ne(p,n,f),Ct(p),St(b,K,p),Ze(K,o.subarray(32)),$e(b,K),Ut(u,b),f-=64,vr(o,0,u,0)){for(a=0;a<f;a++)n[a]=0;return-1}for(a=0;a<f;a++)n[a]=o[a+64];return f}x(Pt,"crypto_sign_open");var Bt=32,Je=24,ve=32,pe=16,_e=32,Qe=32,Ce=32,Pe=32,Tt=32,Tn=Je,_i=ve,Ci=pe,kr=64,ie=32,he=64,Dt=32,It=64;t.lowlevel={crypto_core_hsalsa20:dr,crypto_stream_xor:Zr,crypto_stream:Br,crypto_stream_salsa20_xor:Mr,crypto_stream_salsa20:_r,crypto_onetimeauth:At,crypto_onetimeauth_verify:mn,crypto_verify_16:yr,crypto_verify_32:vr,crypto_secretbox:mt,crypto_secretbox_open:wt,crypto_scalarmult:Ve,crypto_scalarmult_base:Xe,crypto_box_beforenm:We,crypto_box_afternm:vn,crypto_box:Ui,crypto_box_open:Si,crypto_box_keypair:Sn,crypto_hash:ne,crypto_sign:Bn,crypto_sign_keypair:vt,crypto_sign_open:Pt,crypto_secretbox_KEYBYTES:Bt,crypto_secretbox_NONCEBYTES:Je,crypto_secretbox_ZEROBYTES:ve,crypto_secretbox_BOXZEROBYTES:pe,crypto_scalarmult_BYTES:_e,crypto_scalarmult_SCALARBYTES:Qe,crypto_box_PUBLICKEYBYTES:Ce,crypto_box_SECRETKEYBYTES:Pe,crypto_box_BEFORENMBYTES:Tt,crypto_box_NONCEBYTES:Tn,crypto_box_ZEROBYTES:_i,crypto_box_BOXZEROBYTES:Ci,crypto_sign_BYTES:kr,crypto_sign_PUBLICKEYBYTES:ie,crypto_sign_SECRETKEYBYTES:he,crypto_sign_SEEDBYTES:Dt,crypto_hash_BYTES:It,gf:e,D:er,L:qe,pack25519:ue,unpack25519:Et,M:W,A:Lr,S:Tr,Z:Nr,pow2523:Un,add:$e,set25519:Gr,modL:_t,scalarmult:St,scalarbase:Ze};function Dn(n,o){if(n.length!==Bt)throw new Error("bad key size");if(o.length!==Je)throw new Error("bad nonce size")}x(Dn,"checkLengths");function Pi(n,o){if(n.length!==Ce)throw new Error("bad public key size");if(o.length!==Pe)throw new Error("bad secret key size")}x(Pi,"checkBoxLengths");function Cr(){for(var n=0;n<arguments.length;n++)if(!(arguments[n]instanceof Uint8Array))throw new TypeError("unexpected type, use Uint8Array")}x(Cr,"checkArrayTypes");function In(n){for(var o=0;o<n.length;o++)n[o]=0}x(In,"cleanup"),t.randomBytes=function(n){var o=new Uint8Array(n);return i(o,n),o},t.secretbox=function(n,o,f){Cr(n,o,f),Dn(f,o);for(var r=new Uint8Array(ve+n.length),a=new Uint8Array(r.length),u=0;u<n.length;u++)r[u+ve]=n[u];return mt(a,r,r.length,o,f),a.subarray(pe)},t.secretbox.open=function(n,o,f){Cr(n,o,f),Dn(f,o);for(var r=new Uint8Array(pe+n.length),a=new Uint8Array(r.length),u=0;u<n.length;u++)r[u+pe]=n[u];return r.length<32||wt(a,r,r.length,o,f)!==0?null:a.subarray(ve)},t.secretbox.keyLength=Bt,t.secretbox.nonceLength=Je,t.secretbox.overheadLength=pe,t.scalarMult=function(n,o){if(Cr(n,o),n.length!==Qe)throw new Error("bad n size");if(o.length!==_e)throw new Error("bad p size");var f=new Uint8Array(_e);return Ve(f,n,o),f},t.scalarMult.base=function(n){if(Cr(n),n.length!==Qe)throw new Error("bad n size");var o=new Uint8Array(_e);return Xe(o,n),o},t.scalarMult.scalarLength=Qe,t.scalarMult.groupElementLength=_e,t.box=function(n,o,f,r){var a=t.box.before(f,r);return t.secretbox(n,o,a)},t.box.before=function(n,o){Cr(n,o),Pi(n,o);var f=new Uint8Array(Tt);return We(f,n,o),f},t.box.after=t.secretbox,t.box.open=function(n,o,f,r){var a=t.box.before(f,r);return t.secretbox.open(n,o,a)},t.box.open.after=t.secretbox.open,t.box.keyPair=function(){var n=new Uint8Array(Ce),o=new Uint8Array(Pe);return Sn(n,o),{publicKey:n,secretKey:o}},t.box.keyPair.fromSecretKey=function(n){if(Cr(n),n.length!==Pe)throw new Error("bad secret key size");var o=new Uint8Array(Ce);return Xe(o,n),{publicKey:o,secretKey:new Uint8Array(n)}},t.box.publicKeyLength=Ce,t.box.secretKeyLength=Pe,t.box.sharedKeyLength=Tt,t.box.nonceLength=Tn,t.box.overheadLength=t.secretbox.overheadLength,t.sign=function(n,o){if(Cr(n,o),o.length!==he)throw new Error("bad secret key size");var f=new Uint8Array(kr+n.length);return Bn(f,n,n.length,o),f},t.sign.open=function(n,o){if(Cr(n,o),o.length!==ie)throw new Error("bad public key size");var f=new Uint8Array(n.length),r=Pt(f,n,n.length,o);if(r<0)return null;for(var a=new Uint8Array(r),u=0;u<a.length;u++)a[u]=f[u];return a},t.sign.detached=function(n,o){for(var f=t.sign(n,o),r=new Uint8Array(kr),a=0;a<r.length;a++)r[a]=f[a];return r},t.sign.detached.verify=function(n,o,f){if(Cr(n,o,f),o.length!==kr)throw new Error("bad signature size");if(f.length!==ie)throw new Error("bad public key size");var r=new Uint8Array(kr+n.length),a=new Uint8Array(kr+n.length),u;for(u=0;u<kr;u++)r[u]=o[u];for(u=0;u<n.length;u++)r[u+kr]=n[u];return Pt(a,r,r.length,f)>=0},t.sign.keyPair=function(){var n=new Uint8Array(ie),o=new Uint8Array(he);return vt(n,o),{publicKey:n,secretKey:o}},t.sign.keyPair.fromSecretKey=function(n){if(Cr(n),n.length!==he)throw new Error("bad secret key size");for(var o=new Uint8Array(ie),f=0;f<o.length;f++)o[f]=n[32+f];return{publicKey:o,secretKey:new Uint8Array(n)}},t.sign.keyPair.fromSeed=function(n){if(Cr(n),n.length!==Dt)throw new Error("bad seed size");for(var o=new Uint8Array(ie),f=new Uint8Array(he),r=0;r<32;r++)f[r]=n[r];return vt(o,f,!0),{publicKey:o,secretKey:f}},t.sign.publicKeyLength=ie,t.sign.secretKeyLength=he,t.sign.seedLength=Dt,t.sign.signatureLength=kr,t.hash=function(n){Cr(n);var o=new Uint8Array(It);return ne(o,n,n.length),o},t.hash.hashLength=It,t.verify=function(n,o){return Cr(n,o),n.length===0||o.length===0||n.length!==o.length?!1:$(n,0,o,0,n.length)===0},t.setPRNG=function(n){i=n},function(){var n=typeof self<"u"?self.crypto||self.msCrypto:null;if(n&&n.getRandomValues){var o=65536;t.setPRNG(function(f,r){var a,u=new Uint8Array(r);for(a=0;a<r;a+=o)n.getRandomValues(u.subarray(a,a+Math.min(r-a,o)));for(a=0;a<r;a++)f[a]=u[a];In(u)})}else typeof Mn<"u"&&(n=yi(),n&&n.randomBytes&&t.setPRNG(function(f,r){var a,u=n.randomBytes(r);for(a=0;a<r;a++)f[a]=u[a];In(u)}))}()})(typeof ht<"u"&&ht.exports?ht.exports:self.nacl=self.nacl||{})});var Nn=(s=>(s[s.B1024=1024]="B1024",s[s.B2048=2048]="B2048",s[s.B4096=4096]="B4096",s))(Nn||{}),Rn=(s=>(s[s.B128=128]="B128",s[s.B192=192]="B192",s[s.B256=256]="B256",s))(Rn||{}),zn=(i=>(i.ECC="ecc",i.RSA="rsa",i))(zn||{}),Mt=(c=>(c.SHA_1="SHA-1",c.SHA_256="SHA-256",c.SHA_384="SHA-384",c.SHA_512="SHA-512",c))(Mt||{}),Lt=(c=>(c.P_256="P-256",c.P_384="P-384",c.P_521="P-521",c.X25519="X25519",c))(Lt||{}),fe=(s=>(s.Sign="signing",s.Exchange="exchange",s.Write="write",s))(fe||{}),Nt=(i=>(i[i.B8=8]="B8",i[i.B16=16]="B16",i))(Nt||{});var mi={};Ur(mi,{AES_GCM:()=>Hr,BASE58_DID_PREFIX:()=>Jr,BLS_DID_PREFIX:()=>at,DEFAULT_CHAR_SIZE:()=>Yr,DEFAULT_ECC_EXCHANGE:()=>Re,DEFAULT_ECC_EXCHANGE_CURVE:()=>Xf,DEFAULT_ECC_WRITE:()=>ze,DEFAULT_HASH_ALGORITHM:()=>ae,DEFAULT_RSA_EXCHANGE:()=>ct,DEFAULT_RSA_SIZE:()=>ot,DEFAULT_RSA_WRITE:()=>yt,DEFAULT_SYMM_ALGORITHM:()=>jr,DEFAULT_SYMM_LENGTH:()=>Fr,ECC_EXCHANGE_ALG:()=>an,ECC_EXCHANGE_NAME:()=>cn,ECC_WRITE_ALG:()=>me,ECC_WRITE_NAME:()=>sn,EDWARDS_DID_PREFIX:()=>st,IV_LENGTH:()=>Rr,KEY_TYPE:()=>Ne,KEY_USE:()=>oi,RSA_ALGORITHM:()=>Qr,RSA_DID_PREFIX:()=>ft,RSA_HASHING_ALGORITHM:()=>it,RSA_SIGN_ALGORITHM:()=>re,RsaKeys:()=>ce,SALT_LENGTH:()=>zr,encrypt:()=>yo,encryptKeyTo:()=>Se,encryptTo:()=>Ai,getPublicKeyAsArrayBuffer:()=>$r,getPublicKeyAsUint8Array:()=>pn,publicKeyToDid:()=>je,verify:()=>co});var Ri=globalThis||window||self,X=Ri.crypto;function Be(t=0){return new Uint8Array(t)}x(Be,"allocUnsafe");function Rt(t,e){e==null&&(e=t.reduce((c,d)=>c+d.length,0));let i=Be(e),s=0;for(let c of t)i.set(c,s),s+=c.length;return i}x(Rt,"concat");var jt={};Ur(jt,{base10:()=>Gi});var No=new Uint8Array(0);function On(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let i=0;i<t.byteLength;i++)if(t[i]!==e[i])return!1;return!0}x(On,"equals");function Vr(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}x(Vr,"coerce");function Yn(t){return new TextEncoder().encode(t)}x(Yn,"fromString");function Hn(t){return new TextDecoder().decode(t)}x(Hn,"toString");function Oi(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var i=new Uint8Array(256),s=0;s<i.length;s++)i[s]=255;for(var c=0;c<t.length;c++){var d=t.charAt(c),E=d.charCodeAt(0);if(i[E]!==255)throw new TypeError(d+" is ambiguous");i[E]=c}var M=t.length,er=t.charAt(0),fr=Math.log(M)/Math.log(256),ir=Math.log(256)/Math.log(M);function br($){if($ instanceof Uint8Array||(ArrayBuffer.isView($)?$=new Uint8Array($.buffer,$.byteOffset,$.byteLength):Array.isArray($)&&($=Uint8Array.from($))),!($ instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if($.length===0)return"";for(var yr=0,vr=0,Kr=0,gr=$.length;Kr!==gr&&$[Kr]===0;)Kr++,yr++;for(var Er=(gr-Kr)*ir+1>>>0,dr=new Uint8Array(Er);Kr!==gr;){for(var hr=$[Kr],Mr=0,_r=Er-1;(hr!==0||Mr<vr)&&_r!==-1;_r--,Mr++)hr+=256*dr[_r]>>>0,dr[_r]=hr%M>>>0,hr=hr/M>>>0;if(hr!==0)throw new Error("Non-zero carry");vr=Mr,Kr++}for(var Br=Er-vr;Br!==Er&&dr[Br]===0;)Br++;for(var Zr=er.repeat(yr);Br<Er;++Br)Zr+=t.charAt(dr[Br]);return Zr}x(br,"encode");function Ir($){if(typeof $!="string")throw new TypeError("Expected String");if($.length===0)return new Uint8Array;var yr=0;if($[yr]!==" "){for(var vr=0,Kr=0;$[yr]===er;)vr++,yr++;for(var gr=($.length-yr)*fr+1>>>0,Er=new Uint8Array(gr);$[yr];){var dr=i[$.charCodeAt(yr)];if(dr===255)return;for(var hr=0,Mr=gr-1;(dr!==0||hr<Kr)&&Mr!==-1;Mr--,hr++)dr+=M*Er[Mr]>>>0,Er[Mr]=dr%256>>>0,dr=dr/256>>>0;if(dr!==0)throw new Error("Non-zero carry");Kr=hr,yr++}if($[yr]!==" "){for(var _r=gr-Kr;_r!==gr&&Er[_r]===0;)_r++;for(var Br=new Uint8Array(vr+(gr-_r)),Zr=vr;_r!==gr;)Br[Zr++]=Er[_r++];return Br}}}x(Ir,"decodeUnsafe");function ye($){var yr=Ir($);if(yr)return yr;throw new Error(`Non-${e} character`)}return x(ye,"decode"),{encode:br,decodeUnsafe:Ir,decode:ye}}x(Oi,"base");var Yi=Oi,Hi=Yi,Fn=Hi;var zt=class{static{x(this,"Encoder")}name;prefix;baseEncode;constructor(e,i,s){this.name=e,this.prefix=i,this.baseEncode=s}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ot=class{static{x(this,"Decoder")}name;prefix;baseDecode;prefixCodePoint;constructor(e,i,s){this.name=e,this.prefix=i;let c=i.codePointAt(0);if(c===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=c,this.baseDecode=s}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Gn(this,e)}},Yt=class{static{x(this,"ComposedDecoder")}decoders;constructor(e){this.decoders=e}or(e){return Gn(this,e)}decode(e){let i=e[0],s=this.decoders[i];if(s!=null)return s.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Gn(t,e){return new Yt({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}x(Gn,"or");var Ht=class{static{x(this,"Codec")}name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,i,s,c){this.name=e,this.prefix=i,this.baseEncode=s,this.baseDecode=c,this.encoder=new zt(e,i,s),this.decoder=new Ot(e,i,c)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ge({name:t,prefix:e,encode:i,decode:s}){return new Ht(t,e,i,s)}x(ge,"from");function qr({name:t,prefix:e,alphabet:i}){let{encode:s,decode:c}=Fn(i,t);return ge({prefix:e,name:t,encode:s,decode:x(d=>Vr(c(d)),"decode")})}x(qr,"baseX");function ji(t,e,i,s){let c={};for(let ir=0;ir<e.length;++ir)c[e[ir]]=ir;let d=t.length;for(;t[d-1]==="=";)--d;let E=new Uint8Array(d*i/8|0),M=0,er=0,fr=0;for(let ir=0;ir<d;++ir){let br=c[t[ir]];if(br===void 0)throw new SyntaxError(`Non-${s} character`);er=er<<i|br,M+=i,M>=8&&(M-=8,E[fr++]=255&er>>M)}if(M>=i||(255&er<<8-M)!==0)throw new SyntaxError("Unexpected end of data");return E}x(ji,"decode");function Fi(t,e,i){let s=e[e.length-1]==="=",c=(1<<i)-1,d="",E=0,M=0;for(let er=0;er<t.length;++er)for(M=M<<8|t[er],E+=8;E>i;)E-=i,d+=e[c&M>>E];if(E!==0&&(d+=e[c&M<<i-E]),s)for(;(d.length*i&7)!==0;)d+="=";return d}x(Fi,"encode");function cr({name:t,prefix:e,bitsPerChar:i,alphabet:s}){return ge({prefix:e,name:t,encode(c){return Fi(c,s,i)},decode(c){return ji(c,s,i,t)}})}x(cr,"rfc4648");var Gi=qr({prefix:"9",name:"base10",alphabet:"0123456789"});var Ft={};Ur(Ft,{base16:()=>ki,base16upper:()=>Vi});var ki=cr({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Vi=cr({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Gt={};Ur(Gt,{base2:()=>Xi});var Xi=cr({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var kt={};Ur(kt,{base256emoji:()=>Ji});var kn=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Wi=kn.reduce((t,e,i)=>(t[i]=e,t),[]),$i=kn.reduce((t,e,i)=>{let s=e.codePointAt(0);if(s==null)throw new Error(`Invalid character: ${e}`);return t[s]=i,t},[]);function Zi(t){return t.reduce((e,i)=>(e+=Wi[i],e),"")}x(Zi,"encode");function qi(t){let e=[];for(let i of t){let s=i.codePointAt(0);if(s==null)throw new Error(`Invalid character: ${i}`);let c=$i[s];if(c==null)throw new Error(`Non-base256emoji character: ${i}`);e.push(c)}return new Uint8Array(e)}x(qi,"decode");var Ji=ge({prefix:"\u{1F680}",name:"base256emoji",encode:Zi,decode:qi});var Vt={};Ur(Vt,{base32:()=>de,base32hex:()=>tf,base32hexpad:()=>ff,base32hexpadupper:()=>of,base32hexupper:()=>nf,base32pad:()=>rf,base32padupper:()=>ef,base32upper:()=>Qi,base32z:()=>af});var de=cr({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Qi=cr({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),rf=cr({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ef=cr({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),tf=cr({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),nf=cr({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ff=cr({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),of=cr({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),af=cr({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Xt={};Ur(Xt,{base36:()=>Te,base36upper:()=>sf});var Te=qr({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),sf=qr({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Wt={};Ur(Wt,{base58btc:()=>Or,base58flickr:()=>cf});var Or=qr({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),cf=qr({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var $t={};Ur($t,{base64:()=>yf,base64pad:()=>xf,base64url:()=>uf,base64urlpad:()=>pf});var yf=cr({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),xf=cr({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),uf=cr({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),pf=cr({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Zt={};Ur(Zt,{base8:()=>hf});var hf=cr({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var qt={};Ur(qt,{identity:()=>gf});var gf=ge({prefix:"\0",name:"identity",encode:x(t=>Hn(t),"encode"),decode:x(t=>Yn(t),"decode")});var na=new TextEncoder,ia=new TextDecoder;var Qt={};Ur(Qt,{identity:()=>zf});var bf=Wn,Vn=128,Af=127,mf=~Af,wf=Math.pow(2,31);function Wn(t,e,i){e=e||[],i=i||0;for(var s=i;t>=wf;)e[i++]=t&255|Vn,t/=128;for(;t&mf;)e[i++]=t&255|Vn,t>>>=7;return e[i]=t|0,Wn.bytes=i-s+1,e}x(Wn,"encode");var Kf=Jt,Ef=128,Xn=127;function Jt(t,s){var i=0,s=s||0,c=0,d=s,E,M=t.length;do{if(d>=M)throw Jt.bytes=0,new RangeError("Could not decode varint");E=t[d++],i+=c<28?(E&Xn)<<c:(E&Xn)*Math.pow(2,c),c+=7}while(E>=Ef);return Jt.bytes=d-s,i}x(Jt,"read");var Uf=Math.pow(2,7),Sf=Math.pow(2,14),vf=Math.pow(2,21),_f=Math.pow(2,28),Cf=Math.pow(2,35),Pf=Math.pow(2,42),Bf=Math.pow(2,49),Tf=Math.pow(2,56),Df=Math.pow(2,63),If=x(function(t){return t<Uf?1:t<Sf?2:t<vf?3:t<_f?4:t<Cf?5:t<Pf?6:t<Bf?7:t<Tf?8:t<Df?9:10},"length"),Mf={encode:bf,decode:Kf,encodingLength:If},Lf=Mf,De=Lf;function Ie(t,e=0){return[De.decode(t,e),De.decode.bytes]}x(Ie,"decode");function le(t,e,i=0){return De.encode(t,e,i),e}x(le,"encodeTo");function be(t){return De.encodingLength(t)}x(be,"encodingLength");function oe(t,e){let i=e.byteLength,s=be(t),c=s+be(i),d=new Uint8Array(c+i);return le(t,d,0),le(i,d,s),d.set(e,c),new Ae(t,i,e,d)}x(oe,"create");function $n(t){let e=Vr(t),[i,s]=Ie(e),[c,d]=Ie(e.subarray(s)),E=e.subarray(s+d);if(E.byteLength!==c)throw new Error("Incorrect length");return new Ae(i,c,E,e)}x($n,"decode");function Zn(t,e){if(t===e)return!0;{let i=e;return t.code===i.code&&t.size===i.size&&i.bytes instanceof Uint8Array&&On(t.bytes,i.bytes)}}x(Zn,"equals");var Ae=class{static{x(this,"Digest")}code;size;digest;bytes;constructor(e,i,s,c){this.code=e,this.size=i,this.digest=s,this.bytes=c}};var qn=0,Nf="identity",Jn=Vr;function Rf(t){return oe(qn,Jn(t))}x(Rf,"digest");var zf={code:qn,name:Nf,encode:Jn,digest:Rf};var tn={};Ur(tn,{sha256:()=>Of,sha512:()=>Yf});function en({name:t,code:e,encode:i}){return new rn(t,e,i)}x(en,"from");var rn=class{static{x(this,"Hasher")}name;code;encode;constructor(e,i,s){this.name=e,this.code=i,this.encode=s}digest(e){if(e instanceof Uint8Array){let i=this.encode(e);return i instanceof Uint8Array?oe(this.code,i):i.then(s=>oe(this.code,s))}else throw Error("Unknown type, must be binary type")}};function ri(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}x(ri,"sha");var Of=en({name:"sha2-256",code:18,encode:ri("SHA-256")}),Yf=en({name:"sha2-512",code:19,encode:ri("SHA-512")});function ei(t,e){let{bytes:i,version:s}=t;switch(s){case 0:return jf(i,nn(t),e??Or.encoder);default:return Ff(i,nn(t),e??de.encoder)}}x(ei,"format");var ti=new WeakMap;function nn(t){let e=ti.get(t);if(e==null){let i=new Map;return ti.set(t,i),i}return e}x(nn,"baseCache");var tt=class t{static{x(this,"CID")}code;version;multihash;bytes;"/";constructor(e,i,s,c){this.code=i,this.version=e,this.multihash=s,this.bytes=c,this["/"]=c}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:i}=this;if(e!==Le)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(i.code!==Gf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(i)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:i}=this.multihash,s=oe(e,i);return t.createV1(this.code,s)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,i){let s=i;return s!=null&&e.code===s.code&&e.version===s.version&&Zn(e.multihash,s.multihash)}toString(e){return ei(this,e)}toJSON(){return{"/":ei(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let i=e;if(i instanceof t)return i;if(i["/"]!=null&&i["/"]===i.bytes||i.asCID===i){let{version:s,code:c,multihash:d,bytes:E}=i;return new t(s,c,d,E??ni(s,c,d.bytes))}else if(i[kf]===!0){let{version:s,multihash:c,code:d}=i,E=$n(c);return t.create(s,d,E)}else return null}static create(e,i,s){if(typeof i!="number")throw new Error("String codecs are no longer supported");if(!(s.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(i!==Le)throw new Error(`Version 0 CID must use dag-pb (code: ${Le}) block encoding`);return new t(e,i,s,s.bytes)}case 1:{let c=ni(e,i,s.bytes);return new t(e,i,s,c)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Le,e)}static createV1(e,i){return t.create(1,e,i)}static decode(e){let[i,s]=t.decodeFirst(e);if(s.length!==0)throw new Error("Incorrect length");return i}static decodeFirst(e){let i=t.inspectBytes(e),s=i.size-i.multihashSize,c=Vr(e.subarray(s,s+i.multihashSize));if(c.byteLength!==i.multihashSize)throw new Error("Incorrect length");let d=c.subarray(i.multihashSize-i.digestSize),E=new Ae(i.multihashCode,i.digestSize,d,c);return[i.version===0?t.createV0(E):t.createV1(i.codec,E),e.subarray(i.size)]}static inspectBytes(e){let i=0,s=x(()=>{let[br,Ir]=Ie(e.subarray(i));return i+=Ir,br},"next"),c=s(),d=Le;if(c===18?(c=0,i=0):d=s(),c!==0&&c!==1)throw new RangeError(`Invalid CID version ${c}`);let E=i,M=s(),er=s(),fr=i+er,ir=fr-E;return{version:c,codec:d,multihashCode:M,digestSize:er,multihashSize:ir,size:fr}}static parse(e,i){let[s,c]=Hf(e,i),d=t.decode(c);if(d.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return nn(d).set(s,e),d}};function Hf(t,e){switch(t[0]){case"Q":{let i=e??Or;return[Or.prefix,i.decode(`${Or.prefix}${t}`)]}case Or.prefix:{let i=e??Or;return[Or.prefix,i.decode(t)]}case de.prefix:{let i=e??de;return[de.prefix,i.decode(t)]}case Te.prefix:{let i=e??Te;return[Te.prefix,i.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}x(Hf,"parseCIDtoBytes");function jf(t,e,i){let{prefix:s}=i;if(s!==Or.prefix)throw Error(`Cannot string encode V0 in ${i.name} encoding`);let c=e.get(s);if(c==null){let d=i.encode(t).slice(1);return e.set(s,d),d}else return c}x(jf,"toStringV0");function Ff(t,e,i){let{prefix:s}=i,c=e.get(s);if(c==null){let d=i.encode(t);return e.set(s,d),d}else return c}x(Ff,"toStringV1");var Le=112,Gf=18;function ni(t,e,i){let s=be(t),c=s+be(e),d=new Uint8Array(c+i.byteLength);return le(t,d,0),le(e,d,s),d.set(i,c),d}x(ni,"encodeCID");var kf=Symbol.for("@ipld/js-cid/CID");var fn={...qt,...Gt,...Zt,...jt,...Ft,...Vt,...Xt,...Wt,...$t,...kt},La={...tn,...Qt};function fi(t,e,i,s){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:i},decoder:{decode:s}}}x(fi,"createCodec");var ii=fi("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),on=fi("ascii","a",t=>{let e="a";for(let i=0;i<t.length;i++)e+=String.fromCharCode(t[i]);return e},t=>{t=t.substring(1);let e=Be(t.length);for(let i=0;i<t.length;i++)e[i]=t.charCodeAt(i);return e}),Vf={utf8:ii,"utf-8":ii,hex:fn.base16,latin1:on,ascii:on,binary:on,...fn},nt=Vf;function lr(t,e="utf8"){let i=nt[e];if(i==null)throw new Error(`Unsupported encoding "${e}"`);return i.decoder.decode(`${i.prefix}${t}`)}x(lr,"fromString");function nr(t,e="utf8"){let i=nt[e];if(i==null)throw new Error(`Unsupported encoding "${e}"`);return i.encoder.encode(t).substring(1)}x(nr,"toString");var di={};Ur(di,{AES:()=>ur,decryptBytes:()=>gi,importAesKey:()=>Ee});var Jr="did:key:z",me="Ed25519",an="X25519",Xf="X25519",sn="Ed25519",cn="X25519",oi={sign:["sign","verify"],encrypt:["deriveKey","deriveBits"]},Qr="RSA-OAEP",re="RSASSA-PKCS1-v1_5",it="SHA-256",ft=new Uint8Array([0,245,2]),ot=2048,ae="SHA-256",Yr=8,Hr="AES-GCM",jr=Hr,Fr=256,Rr=12,at=new Uint8Array([234,1]),st=new Uint8Array([237,1]),Ne={RSA:"rsa",Edwards:"ed25519",BLS:"bls12-381"},ct="rsa-exchange-key",yt="rsa-write-key",Re="ecc-exchange",ze="ecc-write",zr=16;var ai=new Error("Invalid key use. Please use 'encryption' or 'signing"),Wf=new Error("Max must be less than 256 and greater than 0");function Pr(t){return new Uint8Array(t).buffer}x(Pr,"toArrayBuffer");async function si(t){return new Uint8Array(await X.subtle.digest("sha-256",t.buffer))}x(si,"sha256");function Dr(t){let e=lr(t,"base64pad");return Pr(e)}x(Dr,"base64ToArrBuf");var se=x((t,e)=>{if(typeof t=="string")return e(t);if(typeof t=="object"&&t.byteLength!==void 0)return new Uint8Array(t).buffer;throw new Error("Improper value. Must be a string, ArrayBuffer, Uint8Array")},"normalizeToBuf");function xt(t){return se(t,Dr)}x(xt,"normalizeBase64ToBuf");var $f=x(t=>se(t,e=>ci(e,8)),"normalizeUtf8ToBuf");function ci(t,e){let i=e===8?new Uint8Array(t.length):new Uint16Array(t.length);for(let s=0,c=t.length;s<c;s++)i[s]=t.charCodeAt(s);return i.buffer}x(ci,"strToArrBuf");var Zf=x(t=>se(t,e=>ci(e,16)),"normalizeUtf16ToBuf");function ee(t,e){switch(e){case 8:return $f(t);default:return Zf(t)}}x(ee,"normalizeUnicodeToBuf");function ut(t){if(!t.startsWith(Jr))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=""+t.substring(Jr.length),i=lr(e,"base58btc"),{keyBuffer:s,type:c}=qf(Pr(i));return{publicKey:new Uint8Array(s),type:c}}x(ut,"didToPublicKey");function qf(t){if(Oe(t,Pr(ft)))return{keyBuffer:t.slice(ft.byteLength),type:Ne.RSA};if(Oe(t,Pr(st)))return{keyBuffer:t.slice(st.byteLength),type:Ne.Edwards};if(Oe(t,Pr(at)))return{keyBuffer:t.slice(at.byteLength),type:Ne.BLS};throw new Error("Unsupported key algorithm. Try using RSA.")}x(qf,"parseMagicBytes");var Jf={equal:x((t,e)=>{let i=new Uint8Array(t),s=new Uint8Array(e);if(i.length!==s.length)return!1;for(let c=0;c<i.length;c++)if(i[c]!==s[c])return!1;return!0},"equal")};function Oe(t,e){return Jf.equal(e,t.slice(0,e.byteLength))}x(Oe,"hasPrefix");function Sr(t){return nr(t instanceof ArrayBuffer?new Uint8Array(t):t,"base64pad")}x(Sr,"toBase64");async function Ye(t,e){let i=typeof t=="string"?Dr(t):Pr(t);return X.subtle.importKey("raw",i,{name:e?.alg||jr,length:e?.length||Fr},!0,["encrypt","decrypt"])}x(Ye,"importKey");function pt(t,{max:e}={max:255}){if(e<1||e>255)throw Wf;let i=new Uint8Array(t);if(e===255)return X.getRandomValues(i),i.buffer;let s=0,c=e+1,d=Math.floor(256/c)*c,E=new Uint8Array(1);for(;s<i.length;)X.getRandomValues(E),E[0]<d&&(i[s]=E[0]%c,s++);return i.buffer}x(pt,"randomBuf");function Xr(t,e){let i=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(Pr(t)),s=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(Pr(e)),c=new Uint8Array(i.length+s.length);return c.set(i),c.set(s,i.length),c.buffer}x(Xr,"joinBufs");async function yn(t,e,i,s){let c=s||!1;if(!Object.values(fe).includes(i))throw new Error("invalid key use");let d=i==="exchange"?Qr:re,E=i==="exchange"?["encrypt","decrypt"]:["sign","verify"];return X.subtle.generateKey({name:d,modulusLength:t,publicExponent:Qf(),hash:{name:e}},c,E)}x(yn,"makeRSAKeypair");function Qf(){return new Uint8Array([1,0,1])}x(Qf,"publicExponent");var ui=Ni(xi(),1);var un={keyTypes:{"bls12-381":{magicBytes:new Uint8Array([234,1]),verify:x(()=>{throw new Error("Not implemented")},"verify")},rsa:{magicBytes:new Uint8Array([0,245,2]),verify:hi},ed25519:{magicBytes:new Uint8Array([237,1]),verify:pi}}};async function ms({message:t,publicKey:e,signature:i}){let s=ro(e),c=gt(e).publicKey;if(s==="ed25519")return pi({message:t,publicKey:c,signature:i});if(s==="rsa")return hi({message:t,publicKey:c,signature:i});throw new Error("Unknown key format")}x(ms,"verify");function ro(t){try{let{type:e}=gt(t);return e}catch{return"unknown"}}x(ro,"getAlgorithm");async function pi({message:t,publicKey:e,signature:i}){let s=t;typeof t=="string"&&(s=lr(t,"utf8"));let c=i;typeof i=="string"&&(c=lr(i,"base64pad"));let d=e;if(typeof e=="string"&&(d=gt(e).publicKey),console.log("Message length:",s.length),console.log("Signature length:",c.length,"expected: 64"),console.log("Public key length:",d.length,"expected: 32"),d.length!==32)throw new Error(`Invalid Ed25519 public key size: ${d.length} bytes, expected 32`);if(c.length!==64)throw new Error(`Invalid Ed25519 signature size: ${c.length} bytes, expected 64`);return ui.default.sign.detached.verify(s,c,d)}x(pi,"ed25519Verify");async function hi({message:t,publicKey:e,signature:i}){let s=e;return typeof e=="string"&&(s=gt(e).publicKey),Wr.verify(t,i,await X.subtle.importKey("spki",Pr(s),{name:re,hash:it},!1,["verify"]),8)}x(hi,"rsaVerify");var Wr={verify:x(async function(e,i,s,c=Yr,d=ae){return X.subtle.verify({name:re,saltLength:zr},typeof s=="string"?await He(s,d,"signing"):s,xt(i),ee(e,c))},"rsaVerify"),sign:x(async function(e,i,s=Yr){return X.subtle.sign({name:re,saltLength:zr},i,ee(e,s))},"sign"),encrypt:x(async function(e,i,s=Yr,c=ae){let d;return typeof i=="string"?d=await He(i,c,"exchange"):d=i instanceof Uint8Array?await He(Pr(i),c,"exchange"):i,X.subtle.encrypt({name:Qr},d,ee(e,s))},"rsaEncrypt"),decrypt:x(async function(e,i){let s=we(i)?i:await io(i,["decrypt"]),c;typeof e=="string"?c=lr(e,"base64pad"):c=e;let d=await X.subtle.decrypt({name:Qr},s,c instanceof Uint8Array?Pr(c):c);return new Uint8Array(d)},"rsaDecrypt")};async function He(t,e,i){eo(i);let s=i==="exchange"?Qr:re,c=i==="exchange"?["encrypt"]:["verify"],d=typeof t=="string"?Dr(no(t)):t;return X.subtle.importKey("spki",d,{name:s,hash:{name:e}},!0,c)}x(He,"importPublicKey");function eo(t){to(t,["signing","exchange"],ai)}x(eo,"checkValidKeyUse");function to(t,e,i){if(!e.some(c=>c===t))throw i}x(to,"checkValid");function no(t){return t.replace(`-----BEGIN PUBLIC KEY-----
|
|
2
2
|
`,"").replace(`
|
|
3
|
-
-----END PUBLIC KEY-----`,"")}x(eo,"stripKeyHeader");function we(t){return yn(t,"algorithm")&&yn(t,"extractable")&&yn(t,"type")}x(we,"isCryptoKey");function yn(t,e){return typeof t=="object"&&t!=null&&e in t}x(yn,"hasProp");function to(t,e){return k.subtle.importKey("spki",t instanceof Uint8Array?Pr(t):t,{name:Jr,hash:nt},!1,e)}x(to,"importRsaKey");async function He(t,e="rsa"){let i=t instanceof CryptoKey?new Uint8Array(await $r(t)):t,s=yi.keyTypes[e]?.magicBytes;if(!s)throw new Error(`Key type '${e}' not supported, available types: ${Object.keys(yi.keyTypes).join(", ")}`);let y=Lt([s,i]);return Ae+nr(y,"base58btc")}x(He,"publicKeyToDid");async function $r(t){return t instanceof CryptoKey?await k.subtle.exportKey("spki",t):await k.subtle.exportKey("spki",t.publicKey)}x($r,"getPublicKeyAsArrayBuffer");async function xn(t){let e=await $r(t);return new Uint8Array(e)}x(xn,"getPublicKeyAsUint8Array");function Ke(t){return new Uint8Array(t).buffer}x(Ke,"toArrayBuffer");var ur={create(t={alg:jr,length:Fr}){let e=t.length||Fr,i=t.alg||jr;return k.subtle.generateKey({name:i,length:e},!0,["encrypt","decrypt"])},export:Object.assign(async t=>{let e=await k.subtle.exportKey("raw",t);return new Uint8Array(e)},{asString:x(async(t,e)=>{let i=await ur.export(t);return e?nr(i,e):Ur(i)},"asString")}),import(t){return Ee(typeof t=="string"?Dr(t):t)},async exportAsString(t){let e=await ur.export(t);return Ur(e)},encrypt:no,async decrypt(t,e,i){let s=we(e)?e:await Ee(e),y=i?await k.subtle.decrypt({name:Hr,iv:Ke(i)},s,typeof t=="string"?Ke(_r(t)):t instanceof Uint8Array?Ke(t):t):await ui(t,s);return new Uint8Array(y)}};function Ee(t,e){return k.subtle.importKey("raw",t instanceof Uint8Array?Ke(t):t,{name:Hr,length:e||256},!0,["encrypt","decrypt"])}x(Ee,"importAesKey");async function no(t,e,i,s){let y=we(e)?e:await Ee(e),g=s?await k.subtle.encrypt({name:Hr,iv:Ke(s)},y,Ke(t)):await io(t,y);return i&&i==="arraybuffer"?g:new Uint8Array(g)}x(no,"encrypt");async function io(t,e,i){let s=re(t,i?.charsize??Yr),y=typeof e=="string"?await Oe(e,i):e,g=i?.iv||ut(Rr),E=await k.subtle.encrypt({name:Hr,iv:g},y,s);return kr(g,E)}x(io,"encryptBytes");async function ui(t,e,i){let s=yt(t),y=typeof e=="string"?await Oe(e,i):e,g=s.slice(0,Rr),E=s.slice(Rr);return await k.subtle.decrypt({name:jr,iv:g},y,E)}x(ui,"decryptBytes");function ht(t){return new Promise((e,i)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>i(t.error)})}x(ht,"promisifyRequest");function fo(t,e){let i,s=x(()=>{if(i)return i;let y=indexedDB.open(t);return y.onupgradeneeded=()=>y.result.createObjectStore(e),i=ht(y),i.then(g=>{g.onclose=()=>i=void 0},()=>{}),i},"getDB");return(y,g)=>s().then(E=>g(E.transaction(e,y).objectStore(e)))}x(fo,"createStore");var un;function pn(){return un||(un=fo("keyval-store","keyval")),un}x(pn,"defaultGetStore");function hn(t,e=pn()){return e("readonly",i=>ht(i.get(t)))}x(hn,"get");function dn(t,e,i=pn()){return i("readwrite",s=>(s.put(e,t),ht(s.transaction)))}x(dn,"set");function hi(t,e=pn()){return e("readwrite",i=>(t.forEach(s=>i.delete(s)),ht(i.transaction)))}x(hi,"delMany");var Ue=class t{static{x(this,"AbstractKeys")}DID;exchangeKey;writeKey;hasPersisted;isSessionOnly;static EXCHANGE_KEY_NAME;static WRITE_KEY_NAME;static _instance;constructor(e){let{keys:i}=e;this.DID=e.did,this.exchangeKey=i.exchange,this.writeKey=i.write,this.hasPersisted=e.hasPersisted,this.isSessionOnly=!!e.isSessionOnly}publicExchangeKeyAsString(e){return this.publicExchangeKey.asString(e)}publicWriteKeyAsString(e){return this.publicWriteKey.asString(e)}get publicWriteKey(){let e=this.writeKey.publicKey;return Object.assign(e,{asString:x(async i=>{let s=await $r(this.writeKey),y=new Uint8Array(s);return i?nr(y,i):Ur(y)},"asString")})}get publicExchangeKey(){let e=this.exchangeKey.publicKey;return Object.assign(e,{asString:x(async i=>{let s=await $r(this.exchangeKey),y=new Uint8Array(s);return i?nr(y,i):Ur(y)},"asString")})}get privateWriteKey(){return this.writeKey.privateKey}get privateExchangeKey(){return this.exchangeKey.privateKey}get deviceName(){return t.deviceName(this.DID)}static deviceName(e){return oo(e)}async persist(){if(this.isSessionOnly)return;let e=this.constructor.EXCHANGE_KEY_NAME,i=this.constructor.WRITE_KEY_NAME;await Promise.all([dn(e,this.exchangeKey),dn(i,this.writeKey)]),this.hasPersisted=!0}async delete(){await hi([this.constructor.EXCHANGE_KEY_NAME,this.constructor.WRITE_KEY_NAME]),this.hasPersisted=!1}async getDeviceName(){return t.deviceName(this.DID)}static _createExchangeKeys(){throw new Error("The child should implement this")}static _createWriteKeys(){throw new Error("The child should implement this")}static async create(e){let i=await this._createExchangeKeys(),s=await this._createWriteKeys(),y=await $r(s),g=await He(new Uint8Array(y),this.TYPE==="ecc"?"ed25519":"rsa"),E=new this({keys:{exchange:i,write:s},did:g,hasPersisted:!1,isSessionOnly:!!e});return this._instance=E,E}static async load(e={session:!1}){if(this._instance)return this._instance;let i=!0,s=await hn(e.encryptionKeyName||this.EXCHANGE_KEY_NAME),y=await hn(e.signingKeyName||this.WRITE_KEY_NAME);s||(i=!1,s=await this._createExchangeKeys()),y||(i=!1,y=await this._createWriteKeys());let g=await $r(y),E=await He(new Uint8Array(g),this.TYPE==="ecc"?"ed25519":"rsa"),M=new this({keys:{exchange:s,write:y},did:E,hasPersisted:i,isSessionOnly:!!e.session});return this._instance=M,M}};async function di(t,e){let{content:i,publicKey:s}=t,y=e||await ur.create(),g=await ur.encrypt(typeof i=="string"?_r(i):i,typeof y=="string"?await ur.import(y):y),E=await gn({key:y,publicKey:s});return kr(E,g)}x(di,"encryptTo");di.asString=async function(t,e){let i=await di(t,e);return nr(new Uint8Array(i),"base64pad")};async function gn({key:t,publicKey:e},i){let s;t instanceof CryptoKey?s=await ur.export(t):s=t;let y=await Wr.encrypt(s,e);return i&&i==="arraybuffer"?y:new Uint8Array(y)}x(gn,"encryptKeyTo");gn.asString=async function({key:t,publicKey:e},i){let s=await gn({key:t,publicKey:e});return i?nr(s,i):Ur(s)};async function oo(t){let e=await oi(new TextEncoder().encode(t.normalize("NFD")));return nr(e,"base32").slice(0,32)}x(oo,"getDeviceName");function ln(t){return new Uint8Array(t).buffer}x(ln,"toArrayBuffer");var se=class t extends Ue{static{x(this,"RsaKeys")}static TYPE="rsa";static INFO="keys";static EXCHANGE_KEY_NAME=st;static WRITE_KEY_NAME=ct;constructor(e){super(e),t.EXCHANGE_KEY_NAME=e.exchangeKeyName||st,t.WRITE_KEY_NAME=e.writeKeyName||ct}static async _createExchangeKeys(){return await cn(ft,oe,"exchange")}static async _createWriteKeys(){return await cn(ft,oe,"write")}async toJson(e){let i=this.publicExchangeKey,s=this.DID,y=await k.subtle.exportKey("spki",i);return{publicExchangeKey:e?nr(new Uint8Array(y),e):Ur(y),DID:s}}async sign(e,i=Yr){let s=this.writeKey,y=await Wr.sign(e,s.privateKey,i);return new Uint8Array(y)}async signAsString(e,i){let s=await this.sign(e,i);return Ur(s)}async encrypt(e,i,s,y,g){let E=i||this.exchangeKey.publicKey,M=s,er=y,fr=M||await ur.create({length:er||g}),ir=await ur.encrypt(typeof e=="string"?_r(e):e,typeof fr=="string"?await ur.import(fr):fr),lr=await Se({key:fr,publicKey:E}),Ir=kr(lr,ir);return new Uint8Array(Ir)}async encryptAsString(e,i,s,y,g){let E=await this.encrypt(e,i,s,y,g);return nr(E,"base64pad")}async decrypt(e,i,s){let y=(typeof i=="number"?i:void 0)||Fr,g=ae(e,Dr),E=g.slice(0,y),M=g.slice(y),er=await this.decryptKey(E);return await ur.decrypt(M,er)}async decryptAsString(e,i,s){let y=await this.decrypt(e,i,s);return nr(y)}async decryptKey(e){return await Wr.decrypt(e,this.exchangeKey.privateKey)}async decryptKeyAsString(e,i){let s=await Wr.decrypt(e,this.exchangeKey.privateKey);return nr(s,i)}async getAesKey(e,i){if(!e)throw new Error("RSA requires an encrypted AES key to decrypt");if(typeof e=="string"){let s=await this.decryptKey(e);return await ur.import(s)}else return e}};Object.assign(se.prototype.sign,{asString:x(async function(t,e){return this.signAsString(t,e)},"asString")});Object.assign(se.prototype.encrypt,{asString:x(async function(t,e,i,s){return this.encryptAsString(t,e,i,s)},"asString")});Object.assign(se.prototype.decrypt,{asString:x(async function(t,e){return this.decryptAsString(t,e)},"asString")});async function ao(t,e,i){let s=xt(i),y=await Ye(ln(s.publicKey),"SHA-256","signing");try{return Wr.verify(t,e,y)}catch{return!1}}x(ao,"verify");Object.assign(se.prototype.decryptKey,{asString:x(async function(t,e){return this.decryptKeyAsString(t,e)},"asString")});async function gi(t,e){let{content:i,publicKey:s}=t,y=e||await ur.create(),g=await ur.encrypt(typeof i=="string"?_r(i):i,typeof y=="string"?await ur.import(y):y),E=await Se({key:y,publicKey:s});return kr(E,g)}x(gi,"encryptTo");gi.asString=async function(t,e){let{content:i,publicKey:s}=t,y=e||await ur.create(),g=await ur.encrypt(typeof i=="string"?_r(i):i,typeof y=="string"?await ur.import(y):y,"arraybuffer"),E=await Se({key:y,publicKey:s}),M=kr(E,g);return nr(new Uint8Array(M),"base64pad")};async function Se({key:t,publicKey:e},i){let s;t instanceof CryptoKey?s=await ur.export(t):s=t;let y=await Wr.encrypt(s,e);return i&&i==="arraybuffer"?y:new Uint8Array(y)}x(Se,"encryptKeyTo");Se.asString=async function({key:t,publicKey:e},i){let s=await Se({key:t,publicKey:e});return i?nr(s,i):Ur(s)};async function so(t,e,i,s){let y=we(e)?e:await Ee(e),g=s?await k.subtle.encrypt({name:Hr,iv:ln(s)},y,ln(t)):await co(t,y);return i&&i==="arraybuffer"?g:new Uint8Array(g)}x(so,"encrypt");async function co(t,e,i){let s=re(t,i?.charsize??Yr),y=typeof e=="string"?await Oe(e,i):e,g=i?.iv||ut(Rr),E=await k.subtle.encrypt({name:Hr,iv:g},y,s);return kr(g,E)}x(co,"encryptBytes");var Ai={};Er(Ai,{EccKeys:()=>ee,default:()=>uo,exportPublicKey:()=>gt,importPublicKey:()=>je,verify:()=>po});var Zs=new Error("Key does not exist. Make sure you properly instantiated the keystore."),qs=new Error("Retrieved a symmetric key when an asymmetric keypair was expected. Please use a different key name."),Js=new Error("Retrieved an asymmetric keypair when an symmetric key was expected. Please use a different key name."),Qs=new Error("ECC is not enabled for this browser. Please use RSA instead."),rc=new Error("Cryptosystem not supported. Please use ECC or RSA"),yo=new Error("Invalid key use. Please use 'exchange' or 'write'"),ec=new Error("Max must be less than 256 and greater than 0");function bi(t){xo(t,["exchange","write","signing"],yo)}x(bi,"checkValidKeyUse");function xo(t,e,i){if(!e.some(y=>y===t))throw i}x(xo,"checkValid");function Fe(t){return new Uint8Array(t).buffer}x(Fe,"toArrayBuffer");var ee=class t extends Ue{static{x(this,"EccKeys")}static TYPE="ecc";static EXCHANGE_KEY_NAME=Re;static WRITE_KEY_NAME=ze;static INFO="keys";constructor(e){super(e),t.EXCHANGE_KEY_NAME=e.exchangeKeyName||Re,t.WRITE_KEY_NAME=e.writeKeyName||ze}get publicExchangeKey(){let e=this.exchangeKey.publicKey;return Object.assign(e,{asString:x(async i=>{let s=await gt(this.exchangeKey),y=new Uint8Array(s);return i?nr(y,i):Ur(s)},"asString")})}get publicWriteKey(){let e=this.writeKey.publicKey;return Object.assign(e,{asString:x(async i=>{let s=await gt(this.writeKey),y=new Uint8Array(s);return i?nr(y,i):Ur(s)},"asString")})}static async _createExchangeKeys(){return await k.subtle.generateKey({name:an},!1,["deriveKey","deriveBits"])}static async _createWriteKeys(){return await k.subtle.generateKey({name:on},!1,["sign","verify"])}static async load(e={session:!1}){if(this._instance)return this._instance;let i=e.encryptionKeyName||Re,s=e.signingKeyName||ze;return super.load({...e,encryptionKeyName:i,signingKeyName:s})}async toJson(e){let i=this.DID,s=await gt(this.exchangeKey);return{publicExchangeKey:e?nr(new Uint8Array(s),e):Ur(s),DID:i}}async encrypt(e,i,s,y,g){let E=new TextEncoder,M=crypto.getRandomValues(new Uint8Array(zr)),er=i||this.exchangeKey.publicKey,fr;typeof er=="string"?fr=await je(er,"X25519","exchange"):fr=er;let ir=y||await dt(this.exchangeKey.privateKey,fr,M,s||t.INFO,g);ir instanceof CryptoKey||(ir=await dt(this.exchangeKey.privateKey,fr,M,s||t.INFO));let lr=crypto.getRandomValues(new Uint8Array(Rr)),Ir=typeof e=="string"?E.encode(e):e,ce=await crypto.subtle.encrypt({name:jr,iv:lr},ir,Fe(Ir)),$=new Uint8Array(M),yr=new Uint8Array(lr),Sr=new Uint8Array(ce),wr=$.length+yr.length+Sr.length,dr=new Uint8Array(wr);return dr.set($,0),dr.set(yr,$.length),dr.set(Sr,$.length+yr.length),dr}async encryptAsString(e,i,s,y,g){let E=await this.encrypt(e,i,s||t.INFO,y,g);return nr(new Uint8Array(E),"base64pad")}async decrypt(e,i,s,y){let g=typeof i=="string"?await je(i,"X25519","write"):i;g||(g=this.publicExchangeKey);let E=ae(e,Dr),M=E.slice(0,zr),er=E.slice(zr,zr+Rr),fr=E.slice(zr+Rr),{privateKey:ir}=this.exchangeKey,lr=await dt(ir,g,M,y||t.INFO);return await crypto.subtle.decrypt({name:s||jr,iv:er},lr,fr)}async decryptAsString(e,i,s,y){let g=await this.decrypt(e,i,s,y);return nr(new Uint8Array(g))}async getAesKey(e,i){e||(e=this.publicExchangeKey);let s;typeof e=="string"?s=await je(e,"X25519","exchange"):s=e;let y=crypto.getRandomValues(new Uint8Array(zr));return await dt(this.exchangeKey.privateKey,s,y,i||t.INFO)}async sign(e,i){let s=new TextEncoder,y;typeof e=="string"?y=s.encode(e):e instanceof ArrayBuffer?y=new Uint8Array(e):y=e;let g=await k.subtle.sign({name:me},this.writeKey.privateKey,Fe(y));return new Uint8Array(g)}async signAsString(e,i){let s=await this.sign(e,i);return nr(s,"base64pad")}};Object.assign(ee.prototype.sign,{asString:x(async function(t,e){let i=await this.sign(t,e);return nr(i,"base64pad")},"asString")});async function gt(t){return await k.subtle.exportKey("raw",t.publicKey)}x(gt,"exportPublicKey");async function je(t,e,i){bi(i);let s=i==="exchange"?fn:me,y=i==="exchange"?[]:["verify"],g=Dr(t),E=e==="X25519"?{name:s}:{name:s,namedCurve:e};return k.subtle.importKey("raw",g,E,!0,y)}x(je,"importPublicKey");var uo={EccKeys:ee,importPublicKey:je};Object.assign(ee.prototype.encrypt,{asString:x(async function(t,e,i,s,y){return this.encryptAsString(t,e,i,s,y)},"asString")});Object.assign(ee.prototype.decrypt,{asString:x(async function(t,e,i){return this.decryptAsString(t,e,i)},"asString")});Object.assign(ee.prototype.sign,{asString:x(async function(t,e){return this.signAsString(t,e)},"asString")});async function po(t,e,i){try{let s=xt(i);if(s.type!=="ed25519")throw new Error(`Expected Ed25519 key for ECC verification, got ${s.type}`);let y=s.publicKey.slice(-32),g=await k.subtle.importKey("raw",y,{name:me},!0,["verify"]),E=new TextEncoder,M;typeof t=="string"?M=E.encode(t):t instanceof ArrayBuffer?M=new Uint8Array(t):M=t;let er;return typeof e=="string"?er=new Uint8Array(Dr(e)):er=e,await k.subtle.verify({name:me},g,Fe(er),Fe(M))}catch{return!1}}x(po,"verify");async function dt(t,e,i,s,y){let g=new TextEncoder,E=await crypto.subtle.deriveBits({name:"X25519",public:e},t,256),M=await crypto.subtle.importKey("raw",E,"HKDF",!1,["deriveKey"]);return crypto.subtle.deriveKey({name:"HKDF",hash:"SHA-256",salt:i instanceof Uint8Array?Fe(i):i,info:g.encode(s)},M,{name:"AES-GCM",length:y||Fr},!1,["encrypt","decrypt"])}x(dt,"deriveKey");})();
|
|
3
|
+
-----END PUBLIC KEY-----`,"")}x(no,"stripKeyHeader");function we(t){return xn(t,"algorithm")&&xn(t,"extractable")&&xn(t,"type")}x(we,"isCryptoKey");function xn(t,e){return typeof t=="object"&&t!=null&&e in t}x(xn,"hasProp");function io(t,e){return X.subtle.importKey("spki",t instanceof Uint8Array?Pr(t):t,{name:Qr,hash:it},!1,e)}x(io,"importRsaKey");async function je(t,e="rsa"){let i=t instanceof CryptoKey?new Uint8Array(await $r(t)):t,s=un.keyTypes[e]?.magicBytes;if(!s)throw new Error(`Key type '${e}' not supported, available types: ${Object.keys(un.keyTypes).join(", ")}`);let c=Rt([s,i]);return Jr+nr(c,"base58btc")}x(je,"publicKeyToDid");async function $r(t){return t instanceof CryptoKey?await X.subtle.exportKey("spki",t):await X.subtle.exportKey("spki",t.publicKey)}x($r,"getPublicKeyAsArrayBuffer");async function pn(t){let e=await $r(t);return new Uint8Array(e)}x(pn,"getPublicKeyAsUint8Array");function gt(t){if(!t.startsWith(Jr))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=t.substr(Jr.length),i=lr(e,"base58btc"),s=Object.entries(un.keyTypes).find(([d,E])=>Oe(i.buffer,E.magicBytes.buffer));if(!s)throw new Error("Unsupported key algorithm.");let c=i.slice(s[1].magicBytes.length);return s[0]==="ed25519"&&c.length===44?{publicKey:c.slice(-32),type:s[0]}:{publicKey:c,type:s[0]}}x(gt,"didToPublicKey");function Ke(t){return new Uint8Array(t).buffer}x(Ke,"toArrayBuffer");var ur={create(t={alg:jr,length:Fr}){let e=t.length||Fr,i=t.alg||jr;return X.subtle.generateKey({name:i,length:e},!0,["encrypt","decrypt"])},export:Object.assign(async t=>{let e=await X.subtle.exportKey("raw",t);return new Uint8Array(e)},{asString:x(async(t,e)=>{let i=await ur.export(t);return e?nr(i,e):Sr(i)},"asString")}),import(t){return Ee(typeof t=="string"?Dr(t):t)},async exportAsString(t){let e=await ur.export(t);return Sr(e)},encrypt:fo,async decrypt(t,e,i){let s=we(e)?e:await Ee(e),c=i?await X.subtle.decrypt({name:Hr,iv:Ke(i)},s,typeof t=="string"?Ke(lr(t)):t instanceof Uint8Array?Ke(t):t):await gi(t,s);return new Uint8Array(c)}};function Ee(t,e){return X.subtle.importKey("raw",t instanceof Uint8Array?Ke(t):t,{name:Hr,length:e||256},!0,["encrypt","decrypt"])}x(Ee,"importAesKey");async function fo(t,e,i,s){let c=we(e)?e:await Ee(e),d=s?await X.subtle.encrypt({name:Hr,iv:Ke(s)},c,Ke(t)):await oo(t,c);return i&&i==="arraybuffer"?d:new Uint8Array(d)}x(fo,"encrypt");async function oo(t,e,i){let s=ee(t,i?.charsize??Yr),c=typeof e=="string"?await Ye(e,i):e,d=i?.iv||pt(Rr),E=await X.subtle.encrypt({name:Hr,iv:d},c,s);return Xr(d,E)}x(oo,"encryptBytes");async function gi(t,e,i){let s=xt(t),c=typeof e=="string"?await Ye(e,i):e,d=s.slice(0,Rr),E=s.slice(Rr);return await X.subtle.decrypt({name:jr,iv:d},c,E)}x(gi,"decryptBytes");function dt(t){return new Promise((e,i)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>i(t.error)})}x(dt,"promisifyRequest");function ao(t,e){let i,s=x(()=>{if(i)return i;let c=indexedDB.open(t);return c.onupgradeneeded=()=>c.result.createObjectStore(e),i=dt(c),i.then(d=>{d.onclose=()=>i=void 0},()=>{}),i},"getDB");return(c,d)=>s().then(E=>d(E.transaction(e,c).objectStore(e)))}x(ao,"createStore");var hn;function gn(){return hn||(hn=ao("keyval-store","keyval")),hn}x(gn,"defaultGetStore");function dn(t,e=gn()){return e("readonly",i=>dt(i.get(t)))}x(dn,"get");function ln(t,e,i=gn()){return i("readwrite",s=>(s.put(e,t),dt(s.transaction)))}x(ln,"set");function li(t,e=gn()){return e("readwrite",i=>(t.forEach(s=>i.delete(s)),dt(i.transaction)))}x(li,"delMany");var Ue=class t{static{x(this,"AbstractKeys")}DID;exchangeKey;writeKey;hasPersisted;isSessionOnly;static EXCHANGE_KEY_NAME;static WRITE_KEY_NAME;static _instance;constructor(e){let{keys:i}=e;this.DID=e.did,this.exchangeKey=i.exchange,this.writeKey=i.write,this.hasPersisted=e.hasPersisted,this.isSessionOnly=!!e.isSessionOnly}publicExchangeKeyAsString(e){return this.publicExchangeKey.asString(e)}publicWriteKeyAsString(e){return this.publicWriteKey.asString(e)}get publicWriteKey(){let e=this.writeKey.publicKey;return Object.assign(e,{asString:x(async i=>{let s=await $r(this.writeKey),c=new Uint8Array(s);return i?nr(c,i):Sr(c)},"asString")})}get publicExchangeKey(){let e=this.exchangeKey.publicKey;return Object.assign(e,{asString:x(async i=>{let s=await $r(this.exchangeKey),c=new Uint8Array(s);return i?nr(c,i):Sr(c)},"asString")})}get privateWriteKey(){return this.writeKey.privateKey}get privateExchangeKey(){return this.exchangeKey.privateKey}get deviceName(){return t.deviceName(this.DID)}static deviceName(e){return so(e)}async persist(){if(this.isSessionOnly)return;let e=this.constructor.EXCHANGE_KEY_NAME,i=this.constructor.WRITE_KEY_NAME;await Promise.all([ln(e,this.exchangeKey),ln(i,this.writeKey)]),this.hasPersisted=!0}async delete(){await li([this.constructor.EXCHANGE_KEY_NAME,this.constructor.WRITE_KEY_NAME]),this.hasPersisted=!1}async getDeviceName(){return t.deviceName(this.DID)}static _createExchangeKeys(){throw new Error("The child should implement this")}static _createWriteKeys(){throw new Error("The child should implement this")}static async create(e){let i=await this._createExchangeKeys(),s=await this._createWriteKeys(),c=await $r(s),d=await je(new Uint8Array(c),this.TYPE==="ecc"?"ed25519":"rsa"),E=new this({keys:{exchange:i,write:s},did:d,hasPersisted:!1,isSessionOnly:!!e});return this._instance=E,E}static async load(e={session:!1}){if(this._instance)return this._instance;let i=!0,s=await dn(e.encryptionKeyName||this.EXCHANGE_KEY_NAME),c=await dn(e.signingKeyName||this.WRITE_KEY_NAME);s||(i=!1,s=await this._createExchangeKeys()),c||(i=!1,c=await this._createWriteKeys());let d=await $r(c),E=await je(new Uint8Array(d),this.TYPE==="ecc"?"ed25519":"rsa"),M=new this({keys:{exchange:s,write:c},did:E,hasPersisted:i,isSessionOnly:!!e.session});return this._instance=M,M}};async function bi(t,e){let{content:i,publicKey:s}=t,c=e||await ur.create(),d=await ur.encrypt(typeof i=="string"?lr(i):i,typeof c=="string"?await ur.import(c):c),E=await bn({key:c,publicKey:s});return Xr(E,d)}x(bi,"encryptTo");bi.asString=async function(t,e){let i=await bi(t,e);return nr(new Uint8Array(i),"base64pad")};async function bn({key:t,publicKey:e},i){let s;t instanceof CryptoKey?s=await ur.export(t):s=t;let c=await Wr.encrypt(s,e);return i&&i==="arraybuffer"?c:new Uint8Array(c)}x(bn,"encryptKeyTo");bn.asString=async function({key:t,publicKey:e},i){let s=await bn({key:t,publicKey:e});return i?nr(s,i):Sr(s)};async function so(t){let e=await si(new TextEncoder().encode(t.normalize("NFD")));return nr(e,"base32").slice(0,32)}x(so,"getDeviceName");function An(t){return new Uint8Array(t).buffer}x(An,"toArrayBuffer");var ce=class t extends Ue{static{x(this,"RsaKeys")}static TYPE="rsa";static INFO="keys";static EXCHANGE_KEY_NAME=ct;static WRITE_KEY_NAME=yt;constructor(e){super(e),t.EXCHANGE_KEY_NAME=e.exchangeKeyName||ct,t.WRITE_KEY_NAME=e.writeKeyName||yt}static async _createExchangeKeys(){return await yn(ot,ae,"exchange")}static async _createWriteKeys(){return await yn(ot,ae,"write")}async toJson(e){let i=this.publicExchangeKey,s=this.DID,c=await X.subtle.exportKey("spki",i);return{publicExchangeKey:e?nr(new Uint8Array(c),e):Sr(c),DID:s}}async sign(e,i=Yr){let s=this.writeKey,c=await Wr.sign(e,s.privateKey,i);return new Uint8Array(c)}async signAsString(e,i){let s=await this.sign(e,i);return Sr(s)}async encrypt(e,i,s,c,d){let E=i||this.exchangeKey.publicKey,M=s,er=c,fr=M||await ur.create({length:er||d}),ir=await ur.encrypt(typeof e=="string"?lr(e):e,typeof fr=="string"?await ur.import(fr):fr),br=await Se({key:fr,publicKey:E}),Ir=Xr(br,ir);return new Uint8Array(Ir)}async encryptAsString(e,i,s,c,d){let E=await this.encrypt(e,i,s,c,d);return nr(E,"base64pad")}async decrypt(e,i,s){let c=(typeof i=="number"?i:void 0)||Fr,d=se(e,Dr),E=d.slice(0,c),M=d.slice(c),er=await this.decryptKey(E);return await ur.decrypt(M,er)}async decryptAsString(e,i,s){let c=await this.decrypt(e,i,s);return nr(c)}async decryptKey(e){return await Wr.decrypt(e,this.exchangeKey.privateKey)}async decryptKeyAsString(e,i){let s=await Wr.decrypt(e,this.exchangeKey.privateKey);return nr(s,i)}async getAesKey(e,i){if(!e)throw new Error("RSA requires an encrypted AES key to decrypt");if(typeof e=="string"){let s=await this.decryptKey(e);return await ur.import(s)}else return e}};Object.assign(ce.prototype.sign,{asString:x(async function(t,e){return this.signAsString(t,e)},"asString")});Object.assign(ce.prototype.encrypt,{asString:x(async function(t,e,i,s){return this.encryptAsString(t,e,i,s)},"asString")});Object.assign(ce.prototype.decrypt,{asString:x(async function(t,e){return this.decryptAsString(t,e)},"asString")});async function co(t,e,i){let s=ut(i),c=await He(An(s.publicKey),"SHA-256","signing");try{return Wr.verify(t,e,c)}catch{return!1}}x(co,"verify");Object.assign(ce.prototype.decryptKey,{asString:x(async function(t,e){return this.decryptKeyAsString(t,e)},"asString")});async function Ai(t,e){let{content:i,publicKey:s}=t,c=e||await ur.create(),d=await ur.encrypt(typeof i=="string"?lr(i):i,typeof c=="string"?await ur.import(c):c),E=await Se({key:c,publicKey:s});return Xr(E,d)}x(Ai,"encryptTo");Ai.asString=async function(t,e){let{content:i,publicKey:s}=t,c=e||await ur.create(),d=await ur.encrypt(typeof i=="string"?lr(i):i,typeof c=="string"?await ur.import(c):c,"arraybuffer"),E=await Se({key:c,publicKey:s}),M=Xr(E,d);return nr(new Uint8Array(M),"base64pad")};async function Se({key:t,publicKey:e},i){let s;t instanceof CryptoKey?s=await ur.export(t):s=t;let c=await Wr.encrypt(s,e);return i&&i==="arraybuffer"?c:new Uint8Array(c)}x(Se,"encryptKeyTo");Se.asString=async function({key:t,publicKey:e},i){let s=await Se({key:t,publicKey:e});return i?nr(s,i):Sr(s)};async function yo(t,e,i,s){let c=we(e)?e:await Ee(e),d=s?await X.subtle.encrypt({name:Hr,iv:An(s)},c,An(t)):await xo(t,c);return i&&i==="arraybuffer"?d:new Uint8Array(d)}x(yo,"encrypt");async function xo(t,e,i){let s=ee(t,i?.charsize??Yr),c=typeof e=="string"?await Ye(e,i):e,d=i?.iv||pt(Rr),E=await X.subtle.encrypt({name:Hr,iv:d},c,s);return Xr(d,E)}x(xo,"encryptBytes");var Ki={};Ur(Ki,{EccKeys:()=>te,default:()=>ho,exportPublicKey:()=>bt,importPublicKey:()=>Fe,verify:()=>go});var Qs=new Error("Key does not exist. Make sure you properly instantiated the keystore."),rc=new Error("Retrieved a symmetric key when an asymmetric keypair was expected. Please use a different key name."),ec=new Error("Retrieved an asymmetric keypair when an symmetric key was expected. Please use a different key name."),tc=new Error("ECC is not enabled for this browser. Please use RSA instead."),nc=new Error("Cryptosystem not supported. Please use ECC or RSA"),uo=new Error("Invalid key use. Please use 'exchange' or 'write'"),ic=new Error("Max must be less than 256 and greater than 0");function wi(t){po(t,["exchange","write","signing"],uo)}x(wi,"checkValidKeyUse");function po(t,e,i){if(!e.some(c=>c===t))throw i}x(po,"checkValid");function Ge(t){return new Uint8Array(t).buffer}x(Ge,"toArrayBuffer");var te=class t extends Ue{static{x(this,"EccKeys")}static TYPE="ecc";static EXCHANGE_KEY_NAME=Re;static WRITE_KEY_NAME=ze;static INFO="keys";constructor(e){super(e),t.EXCHANGE_KEY_NAME=e.exchangeKeyName||Re,t.WRITE_KEY_NAME=e.writeKeyName||ze}get publicExchangeKey(){let e=this.exchangeKey.publicKey;return Object.assign(e,{asString:x(async i=>{let s=await bt(this.exchangeKey),c=new Uint8Array(s);return i?nr(c,i):Sr(s)},"asString")})}get publicWriteKey(){let e=this.writeKey.publicKey;return Object.assign(e,{asString:x(async i=>{let s=await bt(this.writeKey),c=new Uint8Array(s);return i?nr(c,i):Sr(s)},"asString")})}static async _createExchangeKeys(){return await X.subtle.generateKey({name:cn},!1,["deriveKey","deriveBits"])}static async _createWriteKeys(){return await X.subtle.generateKey({name:sn},!1,["sign","verify"])}static async load(e={session:!1}){if(this._instance)return this._instance;let i=e.encryptionKeyName||Re,s=e.signingKeyName||ze;return super.load({...e,encryptionKeyName:i,signingKeyName:s})}async toJson(e){let i=this.DID,s=await bt(this.exchangeKey);return{publicExchangeKey:e?nr(new Uint8Array(s),e):Sr(s),DID:i}}async encrypt(e,i,s,c,d){let E=new TextEncoder,M=crypto.getRandomValues(new Uint8Array(zr)),er=i||this.exchangeKey.publicKey,fr;typeof er=="string"?fr=await Fe(er,"X25519","exchange"):fr=er;let ir=c||await lt(this.exchangeKey.privateKey,fr,M,s||t.INFO,d);ir instanceof CryptoKey||(ir=await lt(this.exchangeKey.privateKey,fr,M,s||t.INFO));let br=crypto.getRandomValues(new Uint8Array(Rr)),Ir=typeof e=="string"?E.encode(e):e,ye=await crypto.subtle.encrypt({name:jr,iv:br},ir,Ge(Ir)),$=new Uint8Array(M),yr=new Uint8Array(br),vr=new Uint8Array(ye),Kr=$.length+yr.length+vr.length,gr=new Uint8Array(Kr);return gr.set($,0),gr.set(yr,$.length),gr.set(vr,$.length+yr.length),gr}async encryptAsString(e,i,s,c,d){let E=await this.encrypt(e,i,s||t.INFO,c,d);return nr(new Uint8Array(E),"base64pad")}async decrypt(e,i,s,c){let d=typeof i=="string"?await Fe(i,"X25519","write"):i;d||(d=this.publicExchangeKey);let E=se(e,Dr),M=E.slice(0,zr),er=E.slice(zr,zr+Rr),fr=E.slice(zr+Rr),{privateKey:ir}=this.exchangeKey,br=await lt(ir,d,M,c||t.INFO);return await crypto.subtle.decrypt({name:s||jr,iv:er},br,fr)}async decryptAsString(e,i,s,c){let d=await this.decrypt(e,i,s,c);return nr(new Uint8Array(d))}async getAesKey(e,i){e||(e=this.publicExchangeKey);let s;typeof e=="string"?s=await Fe(e,"X25519","exchange"):s=e;let c=crypto.getRandomValues(new Uint8Array(zr));return await lt(this.exchangeKey.privateKey,s,c,i||t.INFO)}async sign(e,i){let s=new TextEncoder,c;typeof e=="string"?c=s.encode(e):e instanceof ArrayBuffer?c=new Uint8Array(e):c=e;let d=await X.subtle.sign({name:me},this.writeKey.privateKey,Ge(c));return new Uint8Array(d)}async signAsString(e,i){let s=await this.sign(e,i);return nr(s,"base64pad")}};Object.assign(te.prototype.sign,{asString:x(async function(t,e){let i=await this.sign(t,e);return nr(i,"base64pad")},"asString")});async function bt(t){return await X.subtle.exportKey("raw",t.publicKey)}x(bt,"exportPublicKey");async function Fe(t,e,i){wi(i);let s=i==="exchange"?an:me,c=i==="exchange"?[]:["verify"],d=Dr(t),E=e==="X25519"?{name:s}:{name:s,namedCurve:e};return X.subtle.importKey("raw",d,E,!0,c)}x(Fe,"importPublicKey");var ho={EccKeys:te,importPublicKey:Fe};Object.assign(te.prototype.encrypt,{asString:x(async function(t,e,i,s,c){return this.encryptAsString(t,e,i,s,c)},"asString")});Object.assign(te.prototype.decrypt,{asString:x(async function(t,e,i){return this.decryptAsString(t,e,i)},"asString")});Object.assign(te.prototype.sign,{asString:x(async function(t,e){return this.signAsString(t,e)},"asString")});async function go(t,e,i){try{let s=ut(i);if(s.type!=="ed25519")throw new Error(`Expected Ed25519 key for ECC verification, got ${s.type}`);let c=s.publicKey.slice(-32),d=await X.subtle.importKey("raw",c,{name:me},!0,["verify"]),E=new TextEncoder,M;typeof t=="string"?M=E.encode(t):t instanceof ArrayBuffer?M=new Uint8Array(t):M=t;let er;return typeof e=="string"?er=new Uint8Array(Dr(e)):er=e,await X.subtle.verify({name:me},d,Ge(er),Ge(M))}catch{return!1}}x(go,"verify");async function lt(t,e,i,s,c){let d=new TextEncoder,E=await crypto.subtle.deriveBits({name:"X25519",public:e},t,256),M=await crypto.subtle.importKey("raw",E,"HKDF",!1,["deriveKey"]);return crypto.subtle.deriveKey({name:"HKDF",hash:"SHA-256",salt:i instanceof Uint8Array?Ge(i):i,info:d.encode(s)},M,{name:"AES-GCM",length:c||Fr},!1,["encrypt","decrypt"])}x(lt,"deriveKey");})();
|