@substrate-system/keys 0.5.0 → 0.5.1
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/dist/_base.min.js +2 -2
- package/dist/_base.min.js.map +4 -4
- package/dist/aes/index.min.js +2 -2
- package/dist/aes/index.min.js.map +3 -3
- package/dist/browser/index.js +118 -34
- package/dist/browser/index.min.js +2 -2
- package/dist/crypto.min.js +2 -2
- package/dist/crypto.min.js.map +4 -4
- package/dist/ecc/index.min.js +2 -2
- package/dist/ecc/index.min.js.map +4 -4
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +4 -4
- package/dist/rsa/index.min.js +2 -2
- package/dist/rsa/index.min.js.map +4 -4
- package/dist/util.d.ts +1 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.min.js +1 -1
- package/dist/util.min.js.map +3 -3
- package/package.json +2 -2
package/dist/browser/index.js
CHANGED
|
@@ -98,8 +98,16 @@
|
|
|
98
98
|
__name(allocUnsafe, "allocUnsafe");
|
|
99
99
|
|
|
100
100
|
// node_modules/uint8arrays/dist/src/util/as-uint8array.js
|
|
101
|
+
function isByteArrayWithArrayBuffer(b) {
|
|
102
|
+
return b?.buffer instanceof ArrayBuffer;
|
|
103
|
+
}
|
|
104
|
+
__name(isByteArrayWithArrayBuffer, "isByteArrayWithArrayBuffer");
|
|
101
105
|
function asUint8Array(buf) {
|
|
102
|
-
|
|
106
|
+
if (isByteArrayWithArrayBuffer(buf)) {
|
|
107
|
+
return buf;
|
|
108
|
+
}
|
|
109
|
+
const b = buf.slice();
|
|
110
|
+
return new Uint8Array(b.buffer, 0, b.byteLength);
|
|
103
111
|
}
|
|
104
112
|
__name(asUint8Array, "asUint8Array");
|
|
105
113
|
|
|
@@ -143,28 +151,57 @@
|
|
|
143
151
|
__name(equals, "equals");
|
|
144
152
|
function coerce(o) {
|
|
145
153
|
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") {
|
|
146
|
-
return o;
|
|
154
|
+
return toArrayBufferBackedArray(o);
|
|
147
155
|
}
|
|
148
156
|
if (o instanceof ArrayBuffer) {
|
|
149
157
|
return new Uint8Array(o);
|
|
150
158
|
}
|
|
151
159
|
if (ArrayBuffer.isView(o)) {
|
|
152
|
-
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
160
|
+
return toArrayBufferBackedArray(new Uint8Array(o.buffer, o.byteOffset, o.byteLength));
|
|
153
161
|
}
|
|
154
162
|
throw new Error("Unknown type, must be binary type");
|
|
155
163
|
}
|
|
156
164
|
__name(coerce, "coerce");
|
|
157
165
|
function fromString(str) {
|
|
158
|
-
|
|
166
|
+
const output = new Uint8Array(str.length);
|
|
167
|
+
for (let i = 0; i < str.length; i++) {
|
|
168
|
+
output[i] = str.charCodeAt(i);
|
|
169
|
+
}
|
|
170
|
+
return output;
|
|
159
171
|
}
|
|
160
172
|
__name(fromString, "fromString");
|
|
173
|
+
var MAX_ARGUMENTS_LENGTH = 4096;
|
|
161
174
|
function toString(b) {
|
|
162
|
-
|
|
175
|
+
const len = b.length;
|
|
176
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
177
|
+
return String.fromCharCode.apply(String, b);
|
|
178
|
+
}
|
|
179
|
+
let res = "";
|
|
180
|
+
let i = 0;
|
|
181
|
+
while (i < len) {
|
|
182
|
+
res += String.fromCharCode.apply(
|
|
183
|
+
String,
|
|
184
|
+
// @ts-expect-error cannot ordinarily apply a Uint8Array
|
|
185
|
+
b.subarray(i, i += MAX_ARGUMENTS_LENGTH)
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
return res;
|
|
163
189
|
}
|
|
164
190
|
__name(toString, "toString");
|
|
191
|
+
function isByteArrayWithArrayBuffer2(b) {
|
|
192
|
+
return b?.buffer instanceof ArrayBuffer;
|
|
193
|
+
}
|
|
194
|
+
__name(isByteArrayWithArrayBuffer2, "isByteArrayWithArrayBuffer");
|
|
195
|
+
function toArrayBufferBackedArray(b) {
|
|
196
|
+
if (isByteArrayWithArrayBuffer2(b)) {
|
|
197
|
+
return b;
|
|
198
|
+
}
|
|
199
|
+
return b.slice();
|
|
200
|
+
}
|
|
201
|
+
__name(toArrayBufferBackedArray, "toArrayBufferBackedArray");
|
|
165
202
|
|
|
166
203
|
// node_modules/multiformats/dist/src/vendor/base-x.js
|
|
167
|
-
function base(ALPHABET, name2) {
|
|
204
|
+
function base(ALPHABET, name2, caseInsensitive) {
|
|
168
205
|
if (ALPHABET.length >= 255) {
|
|
169
206
|
throw new TypeError("Alphabet too long");
|
|
170
207
|
}
|
|
@@ -179,6 +216,16 @@
|
|
|
179
216
|
throw new TypeError(x + " is ambiguous");
|
|
180
217
|
}
|
|
181
218
|
BASE_MAP[xc] = i;
|
|
219
|
+
if (caseInsensitive) {
|
|
220
|
+
var xl = x.toLowerCase().charCodeAt(0);
|
|
221
|
+
var xu = x.toUpperCase().charCodeAt(0);
|
|
222
|
+
if (xl !== xc) {
|
|
223
|
+
BASE_MAP[xl] = i;
|
|
224
|
+
}
|
|
225
|
+
if (xu !== xc) {
|
|
226
|
+
BASE_MAP[xu] = i;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
182
229
|
}
|
|
183
230
|
var BASE = ALPHABET.length;
|
|
184
231
|
var LEADER = ALPHABET.charAt(0);
|
|
@@ -253,7 +300,11 @@
|
|
|
253
300
|
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
254
301
|
var b256 = new Uint8Array(size);
|
|
255
302
|
while (source[psz]) {
|
|
256
|
-
var
|
|
303
|
+
var charCode = source.charCodeAt(psz);
|
|
304
|
+
if (charCode > 255) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
var carry = BASE_MAP[charCode];
|
|
257
308
|
if (carry === 255) {
|
|
258
309
|
return;
|
|
259
310
|
}
|
|
@@ -413,8 +464,8 @@
|
|
|
413
464
|
return new Codec(name2, prefix, encode5, decode6);
|
|
414
465
|
}
|
|
415
466
|
__name(from, "from");
|
|
416
|
-
function baseX({ name: name2, prefix, alphabet: alphabet2 }) {
|
|
417
|
-
const { encode: encode5, decode: decode6 } = base_x_default(alphabet2, name2);
|
|
467
|
+
function baseX({ name: name2, prefix, alphabet: alphabet2, caseInsensitive = false }) {
|
|
468
|
+
const { encode: encode5, decode: decode6 } = base_x_default(alphabet2, name2, caseInsensitive);
|
|
418
469
|
return from({
|
|
419
470
|
prefix,
|
|
420
471
|
name: name2,
|
|
@@ -475,16 +526,29 @@
|
|
|
475
526
|
return out;
|
|
476
527
|
}
|
|
477
528
|
__name(encode, "encode");
|
|
478
|
-
function createAlphabetIdx(alphabet2) {
|
|
529
|
+
function createAlphabetIdx(alphabet2, caseInsensitive) {
|
|
479
530
|
const alphabetIdx = {};
|
|
480
531
|
for (let i = 0; i < alphabet2.length; ++i) {
|
|
532
|
+
if (alphabet2[i] === "=") {
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
481
535
|
alphabetIdx[alphabet2[i]] = i;
|
|
536
|
+
if (caseInsensitive) {
|
|
537
|
+
const lower = alphabet2[i].toLowerCase();
|
|
538
|
+
const upper = alphabet2[i].toUpperCase();
|
|
539
|
+
if (lower !== alphabet2[i]) {
|
|
540
|
+
alphabetIdx[lower] = i;
|
|
541
|
+
}
|
|
542
|
+
if (upper !== alphabet2[i]) {
|
|
543
|
+
alphabetIdx[upper] = i;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
482
546
|
}
|
|
483
547
|
return alphabetIdx;
|
|
484
548
|
}
|
|
485
549
|
__name(createAlphabetIdx, "createAlphabetIdx");
|
|
486
|
-
function rfc4648({ name: name2, prefix, bitsPerChar, alphabet: alphabet2 }) {
|
|
487
|
-
const alphabetIdx = createAlphabetIdx(alphabet2);
|
|
550
|
+
function rfc4648({ name: name2, prefix, bitsPerChar, alphabet: alphabet2, caseInsensitive = false }) {
|
|
551
|
+
const alphabetIdx = createAlphabetIdx(alphabet2, caseInsensitive);
|
|
488
552
|
return from({
|
|
489
553
|
prefix,
|
|
490
554
|
name: name2,
|
|
@@ -515,13 +579,15 @@
|
|
|
515
579
|
prefix: "f",
|
|
516
580
|
name: "base16",
|
|
517
581
|
alphabet: "0123456789abcdef",
|
|
518
|
-
bitsPerChar: 4
|
|
582
|
+
bitsPerChar: 4,
|
|
583
|
+
caseInsensitive: true
|
|
519
584
|
});
|
|
520
585
|
var base16upper = rfc4648({
|
|
521
586
|
prefix: "F",
|
|
522
587
|
name: "base16upper",
|
|
523
588
|
alphabet: "0123456789ABCDEF",
|
|
524
|
-
bitsPerChar: 4
|
|
589
|
+
bitsPerChar: 4,
|
|
590
|
+
caseInsensitive: true
|
|
525
591
|
});
|
|
526
592
|
|
|
527
593
|
// node_modules/multiformats/dist/src/bases/base2.js
|
|
@@ -601,49 +667,57 @@
|
|
|
601
667
|
prefix: "b",
|
|
602
668
|
name: "base32",
|
|
603
669
|
alphabet: "abcdefghijklmnopqrstuvwxyz234567",
|
|
604
|
-
bitsPerChar: 5
|
|
670
|
+
bitsPerChar: 5,
|
|
671
|
+
caseInsensitive: true
|
|
605
672
|
});
|
|
606
673
|
var base32upper = rfc4648({
|
|
607
674
|
prefix: "B",
|
|
608
675
|
name: "base32upper",
|
|
609
676
|
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
|
610
|
-
bitsPerChar: 5
|
|
677
|
+
bitsPerChar: 5,
|
|
678
|
+
caseInsensitive: true
|
|
611
679
|
});
|
|
612
680
|
var base32pad = rfc4648({
|
|
613
681
|
prefix: "c",
|
|
614
682
|
name: "base32pad",
|
|
615
683
|
alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
|
|
616
|
-
bitsPerChar: 5
|
|
684
|
+
bitsPerChar: 5,
|
|
685
|
+
caseInsensitive: true
|
|
617
686
|
});
|
|
618
687
|
var base32padupper = rfc4648({
|
|
619
688
|
prefix: "C",
|
|
620
689
|
name: "base32padupper",
|
|
621
690
|
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
|
|
622
|
-
bitsPerChar: 5
|
|
691
|
+
bitsPerChar: 5,
|
|
692
|
+
caseInsensitive: true
|
|
623
693
|
});
|
|
624
694
|
var base32hex = rfc4648({
|
|
625
695
|
prefix: "v",
|
|
626
696
|
name: "base32hex",
|
|
627
697
|
alphabet: "0123456789abcdefghijklmnopqrstuv",
|
|
628
|
-
bitsPerChar: 5
|
|
698
|
+
bitsPerChar: 5,
|
|
699
|
+
caseInsensitive: true
|
|
629
700
|
});
|
|
630
701
|
var base32hexupper = rfc4648({
|
|
631
702
|
prefix: "V",
|
|
632
703
|
name: "base32hexupper",
|
|
633
704
|
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
|
|
634
|
-
bitsPerChar: 5
|
|
705
|
+
bitsPerChar: 5,
|
|
706
|
+
caseInsensitive: true
|
|
635
707
|
});
|
|
636
708
|
var base32hexpad = rfc4648({
|
|
637
709
|
prefix: "t",
|
|
638
710
|
name: "base32hexpad",
|
|
639
711
|
alphabet: "0123456789abcdefghijklmnopqrstuv=",
|
|
640
|
-
bitsPerChar: 5
|
|
712
|
+
bitsPerChar: 5,
|
|
713
|
+
caseInsensitive: true
|
|
641
714
|
});
|
|
642
715
|
var base32hexpadupper = rfc4648({
|
|
643
716
|
prefix: "T",
|
|
644
717
|
name: "base32hexpadupper",
|
|
645
718
|
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
|
|
646
|
-
bitsPerChar: 5
|
|
719
|
+
bitsPerChar: 5,
|
|
720
|
+
caseInsensitive: true
|
|
647
721
|
});
|
|
648
722
|
var base32z = rfc4648({
|
|
649
723
|
prefix: "h",
|
|
@@ -661,12 +735,14 @@
|
|
|
661
735
|
var base36 = baseX({
|
|
662
736
|
prefix: "k",
|
|
663
737
|
name: "base36",
|
|
664
|
-
alphabet: "0123456789abcdefghijklmnopqrstuvwxyz"
|
|
738
|
+
alphabet: "0123456789abcdefghijklmnopqrstuvwxyz",
|
|
739
|
+
caseInsensitive: true
|
|
665
740
|
});
|
|
666
741
|
var base36upper = baseX({
|
|
667
742
|
prefix: "K",
|
|
668
743
|
name: "base36upper",
|
|
669
|
-
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
744
|
+
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
|
745
|
+
caseInsensitive: true
|
|
670
746
|
});
|
|
671
747
|
|
|
672
748
|
// node_modules/multiformats/dist/src/bases/base58.js
|
|
@@ -739,8 +815,8 @@
|
|
|
739
815
|
var identity = from({
|
|
740
816
|
prefix: "\0",
|
|
741
817
|
name: "identity",
|
|
742
|
-
encode: /* @__PURE__ */ __name((buf) => toString(buf), "encode"),
|
|
743
|
-
decode: /* @__PURE__ */ __name((str) => fromString(str), "decode")
|
|
818
|
+
encode: /* @__PURE__ */ __name((buf) => toString(coerce(buf)), "encode"),
|
|
819
|
+
decode: /* @__PURE__ */ __name((str) => coerce(fromString(str)), "decode")
|
|
744
820
|
});
|
|
745
821
|
|
|
746
822
|
// node_modules/multiformats/dist/src/codecs/json.js
|
|
@@ -817,7 +893,14 @@
|
|
|
817
893
|
// node_modules/multiformats/dist/src/varint.js
|
|
818
894
|
function decode4(data, offset = 0) {
|
|
819
895
|
const code2 = varint_default.decode(data, offset);
|
|
820
|
-
|
|
896
|
+
const length2 = varint_default.decode.bytes;
|
|
897
|
+
if (length2 > 9) {
|
|
898
|
+
throw new RangeError("Invalid varint: too long");
|
|
899
|
+
}
|
|
900
|
+
if (length2 > 1 && data[offset + length2 - 1] === 0) {
|
|
901
|
+
throw new RangeError("Invalid varint: not minimally encoded");
|
|
902
|
+
}
|
|
903
|
+
return [code2, length2];
|
|
821
904
|
}
|
|
822
905
|
__name(decode4, "decode");
|
|
823
906
|
function encodeTo(int, target, offset = 0) {
|
|
@@ -876,8 +959,8 @@
|
|
|
876
959
|
constructor(code2, size, digest2, bytes) {
|
|
877
960
|
this.code = code2;
|
|
878
961
|
this.size = size;
|
|
879
|
-
this.digest = digest2;
|
|
880
|
-
this.bytes = bytes;
|
|
962
|
+
this.digest = toArrayBufferBackedArray(digest2);
|
|
963
|
+
this.bytes = toArrayBufferBackedArray(bytes);
|
|
881
964
|
}
|
|
882
965
|
};
|
|
883
966
|
|
|
@@ -1013,8 +1096,8 @@
|
|
|
1013
1096
|
this.code = code2;
|
|
1014
1097
|
this.version = version;
|
|
1015
1098
|
this.multihash = multihash;
|
|
1016
|
-
this.bytes = bytes;
|
|
1017
|
-
this["/"] = bytes;
|
|
1099
|
+
this.bytes = toArrayBufferBackedArray(bytes);
|
|
1100
|
+
this["/"] = this.bytes;
|
|
1018
1101
|
}
|
|
1019
1102
|
/**
|
|
1020
1103
|
* Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
|
|
@@ -1217,10 +1300,11 @@
|
|
|
1217
1300
|
if (version === 18) {
|
|
1218
1301
|
version = 0;
|
|
1219
1302
|
offset = 0;
|
|
1220
|
-
} else {
|
|
1303
|
+
} else if (version === 1) {
|
|
1221
1304
|
codec = next();
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1305
|
+
} else if (version === 0) {
|
|
1306
|
+
throw new RangeError("Invalid CID version, v0 is always implicit");
|
|
1307
|
+
} else {
|
|
1224
1308
|
throw new RangeError(`Invalid CID version ${version}`);
|
|
1225
1309
|
}
|
|
1226
1310
|
const prefixSize = offset;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";(()=>{var Mr=Object.defineProperty;var s=(r,e)=>Mr(r,"name",{value:e,configurable:!0});var v=(r,e)=>{for(var t in e)Mr(r,t,{get:e[t],enumerable:!0})};var Rr=(n=>(n[n.B1024=1024]="B1024",n[n.B2048=2048]="B2048",n[n.B4096=4096]="B4096",n))(Rr||{}),Or=(n=>(n[n.B128=128]="B128",n[n.B192=192]="B192",n[n.B256=256]="B256",n))(Or||{}),zr=(t=>(t.ECC="ecc",t.RSA="rsa",t))(zr||{}),Je=(i=>(i.SHA_1="SHA-1",i.SHA_256="SHA-256",i.SHA_384="SHA-384",i.SHA_512="SHA-512",i))(Je||{}),Ze=(i=>(i.P_256="P-256",i.P_384="P-384",i.P_521="P-521",i.X25519="X25519",i))(Ze||{}),re=(n=>(n.Sign="signing",n.Exchange="exchange",n.Write="write",n))(re||{}),Qe=(t=>(t[t.B8=8]="B8",t[t.B16=16]="B16",t))(Qe||{});var bt={};v(bt,{AES_GCM:()=>H,AES_GCM_TAG_LENGTH:()=>Er,BASE58_DID_PREFIX:()=>V,BLS_DID_PREFIX:()=>Ge,DEFAULT_CHAR_SIZE:()=>z,DEFAULT_ECC_EXCHANGE:()=>Cr,DEFAULT_ECC_EXCHANGE_CURVE:()=>kn,DEFAULT_ECC_WRITE:()=>Pr,DEFAULT_HASH_ALGORITHM:()=>ne,DEFAULT_RSA_EXCHANGE:()=>Ur,DEFAULT_RSA_SIZE:()=>He,DEFAULT_RSA_WRITE:()=>Sr,DEFAULT_SYMM_ALGORITHM:()=>I,DEFAULT_SYMM_LENGTH:()=>q,ECC_EXCHANGE_ALGORITHM:()=>Ce,ECC_WRITE_ALGORITHM:()=>te,EDWARDS_DID_PREFIX:()=>Fe,IV_LENGTH:()=>T,KEY_TYPE:()=>Pe,KEY_USE:()=>ct,RSA_ALGORITHM:()=>Y,RSA_DID_PREFIX:()=>ze,RSA_HASHING_ALGORITHM:()=>Oe,RSA_SIGN_ALGORITHM:()=>$,RsaKeys:()=>oe,SALT_LENGTH:()=>C,WRAP_FORMAT_VERSION:()=>Ve,X25519_PUBLIC_KEY_LENGTH:()=>O,encrypt:()=>ni,encryptKeyTo:()=>Ke,encryptTo:()=>Kt,getPublicKeyAsArrayBuffer:()=>Z,getPublicKeyAsUint8Array:()=>Tr,publicKeyToDid:()=>De,verify:()=>ti});function be(r=0){return new Uint8Array(r)}s(be,"allocUnsafe");function er(r,e){e==null&&(e=r.reduce((i,o)=>i+o.length,0));let t=be(e),n=0;for(let i of r)t.set(i,n),n+=i.length;return t}s(er,"concat");var sr={};v(sr,{base10:()=>_t});var Ui=new Uint8Array(0);function Hr(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}s(Hr,"equals");function F(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}s(F,"coerce");function Gr(r){return new TextEncoder().encode(r)}s(Gr,"fromString");function Fr(r){return new TextDecoder().decode(r)}s(Fr,"toString");function Ct(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),a=o.charCodeAt(0);if(t[a]!==255)throw new TypeError(o+" is ambiguous");t[a]=i}var y=r.length,c=r.charAt(0),u=Math.log(y)/Math.log(256),g=Math.log(256)/Math.log(y);function b(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var h=0,B=0,U=0,x=p.length;U!==x&&p[U]===0;)U++,h++;for(var E=(x-U)*g+1>>>0,P=new Uint8Array(E);U!==x;){for(var D=p[U],M=0,N=E-1;(D!==0||M<B)&&N!==-1;N--,M++)D+=256*P[N]>>>0,P[N]=D%y>>>0,D=D/y>>>0;if(D!==0)throw new Error("Non-zero carry");B=M,U++}for(var G=E-B;G!==E&&P[G]===0;)G++;for(var Le=c.repeat(h);G<E;++G)Le+=r.charAt(P[G]);return Le}s(b,"encode");function w(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var h=0;if(p[h]!==" "){for(var B=0,U=0;p[h]===c;)B++,h++;for(var x=(p.length-h)*u+1>>>0,E=new Uint8Array(x);p[h];){var P=t[p.charCodeAt(h)];if(P===255)return;for(var D=0,M=x-1;(P!==0||D<U)&&M!==-1;M--,D++)P+=y*E[M]>>>0,E[M]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");U=D,h++}if(p[h]!==" "){for(var N=x-U;N!==x&&E[N]===0;)N++;for(var G=new Uint8Array(B+(x-N)),Le=B;N!==x;)G[Le++]=E[N++];return G}}}s(w,"decodeUnsafe");function k(p){var h=w(p);if(h)return h;throw new Error(`Non-${e} character`)}return s(k,"decode"),{encode:b,decodeUnsafe:w,decode:k}}s(Ct,"base");var Pt=Ct,Bt=Pt,Wr=Bt;var rr=class{static{s(this,"Encoder")}name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},tr=class{static{s(this,"Decoder")}name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let i=t.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,this.baseDecode=n}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 jr(this,e)}},nr=class{static{s(this,"ComposedDecoder")}decoders;constructor(e){this.decoders=e}or(e){return jr(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function jr(r,e){return new nr({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}s(jr,"or");var ir=class{static{s(this,"Codec")}name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,i){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new rr(e,t,n),this.decoder=new tr(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ye({name:r,prefix:e,encode:t,decode:n}){return new ir(r,e,t,n)}s(ye,"from");function X({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=Wr(t,r);return ye({prefix:e,name:r,encode:n,decode:s(o=>F(i(o)),"decode")})}s(X,"baseX");function vt(r,e,t,n){let i=r.length;for(;r[i-1]==="=";)--i;let o=new Uint8Array(i*t/8|0),a=0,y=0,c=0;for(let u=0;u<i;++u){let g=e[r[u]];if(g===void 0)throw new SyntaxError(`Non-${n} character`);y=y<<t|g,a+=t,a>=8&&(a-=8,o[c++]=255&y>>a)}if(a>=t||(255&y<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return o}s(vt,"decode");function Tt(r,e,t){let n=e[e.length-1]==="=",i=(1<<t)-1,o="",a=0,y=0;for(let c=0;c<r.length;++c)for(y=y<<8|r[c],a+=8;a>t;)a-=t,o+=e[i&y>>a];if(a!==0&&(o+=e[i&y<<t-a]),n)for(;(o.length*t&7)!==0;)o+="=";return o}s(Tt,"encode");function Dt(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}s(Dt,"createAlphabetIdx");function A({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let i=Dt(n);return ye({prefix:e,name:r,encode(o){return Tt(o,n,t)},decode(o){return vt(o,i,t,r)}})}s(A,"rfc4648");var _t=X({prefix:"9",name:"base10",alphabet:"0123456789"});var or={};v(or,{base16:()=>It,base16upper:()=>Nt});var It=A({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Nt=A({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ar={};v(ar,{base2:()=>Lt});var Lt=A({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var yr={};v(yr,{base256emoji:()=>zt});var Xr=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}"),kt=Xr.reduce((r,e,t)=>(r[t]=e,r),[]),Mt=Xr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Rt(r){return r.reduce((e,t)=>(e+=kt[t],e),"")}s(Rt,"encode");function Ot(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let i=Mt[n];if(i==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(i)}return new Uint8Array(e)}s(Ot,"decode");var zt=ye({prefix:"\u{1F680}",name:"base256emoji",encode:Rt,decode:Ot});var cr={};v(cr,{base32:()=>ce,base32hex:()=>Vt,base32hexpad:()=>jt,base32hexpadupper:()=>Xt,base32hexupper:()=>Wt,base32pad:()=>Gt,base32padupper:()=>Ft,base32upper:()=>Ht,base32z:()=>Yt});var ce=A({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ht=A({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Gt=A({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ft=A({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Vt=A({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Wt=A({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),jt=A({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Xt=A({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Yt=A({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var pr={};v(pr,{base36:()=>we,base36upper:()=>$t});var we=X({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),$t=X({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ur={};v(ur,{base58btc:()=>R,base58flickr:()=>qt});var R=X({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),qt=X({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var fr={};v(fr,{base64:()=>Jt,base64pad:()=>Zt,base64url:()=>Qt,base64urlpad:()=>en});var Jt=A({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Zt=A({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Qt=A({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),en=A({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var lr={};v(lr,{base8:()=>rn});var rn=A({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var gr={};v(gr,{identity:()=>tn});var tn=ye({prefix:"\0",name:"identity",encode:s(r=>Fr(r),"encode"),decode:s(r=>Gr(r),"decode")});var Wi=new TextEncoder,ji=new TextDecoder;var mr={};v(mr,{identity:()=>Cn});var on=qr,Yr=128,an=127,yn=~an,cn=Math.pow(2,31);function qr(r,e,t){e=e||[],t=t||0;for(var n=t;r>=cn;)e[t++]=r&255|Yr,r/=128;for(;r&yn;)e[t++]=r&255|Yr,r>>>=7;return e[t]=r|0,qr.bytes=t-n+1,e}s(qr,"encode");var pn=hr,un=128,$r=127;function hr(r,n){var t=0,n=n||0,i=0,o=n,a,y=r.length;do{if(o>=y)throw hr.bytes=0,new RangeError("Could not decode varint");a=r[o++],t+=i<28?(a&$r)<<i:(a&$r)*Math.pow(2,i),i+=7}while(a>=un);return hr.bytes=o-n,t}s(hr,"read");var fn=Math.pow(2,7),ln=Math.pow(2,14),gn=Math.pow(2,21),hn=Math.pow(2,28),mn=Math.pow(2,35),dn=Math.pow(2,42),An=Math.pow(2,49),Kn=Math.pow(2,56),bn=Math.pow(2,63),wn=s(function(r){return r<fn?1:r<ln?2:r<gn?3:r<hn?4:r<mn?5:r<dn?6:r<An?7:r<Kn?8:r<bn?9:10},"length"),xn={encode:on,decode:pn,encodingLength:wn},En=xn,xe=En;function Ee(r,e=0){return[xe.decode(r,e),xe.decode.bytes]}s(Ee,"decode");function pe(r,e,t=0){return xe.encode(r,e,t),e}s(pe,"encodeTo");function ue(r){return xe.encodingLength(r)}s(ue,"encodingLength");function le(r,e){let t=e.byteLength,n=ue(r),i=n+ue(t),o=new Uint8Array(i+t);return pe(r,o,0),pe(t,o,n),o.set(e,i),new fe(r,t,e,o)}s(le,"create");function Jr(r){let e=F(r),[t,n]=Ee(e),[i,o]=Ee(e.subarray(n)),a=e.subarray(n+o);if(a.byteLength!==i)throw new Error("Incorrect length");return new fe(t,i,a,e)}s(Jr,"decode");function Zr(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Hr(r.bytes,t.bytes)}}s(Zr,"equals");var fe=class{static{s(this,"Digest")}code;size;digest;bytes;constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};var Qr=0,Un="identity",et=F;function Sn(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return le(Qr,et(r))}s(Sn,"digest");var Cn={code:Qr,name:Un,encode:et,digest:Sn};var Kr={};v(Kr,{sha256:()=>Bn,sha512:()=>vn});var Pn=20;function Ar({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:i}){return new dr(r,e,t,n,i)}s(Ar,"from");var dr=class{static{s(this,"Hasher")}name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,i,o){this.name=e,this.code=t,this.encode=n,this.minDigestLength=i??Pn,this.maxDigestLength=o}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?rt(n,this.code,t?.truncate):n.then(i=>rt(i,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function rt(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return le(e,r)}s(rt,"createDigest");function nt(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}s(nt,"sha");var Bn=Ar({name:"sha2-256",code:18,encode:nt("SHA-256")}),vn=Ar({name:"sha2-512",code:19,encode:nt("SHA-512")});function it(r,e){let{bytes:t,version:n}=r;return n===0?Dn(t,br(r),e??R.encoder):_n(t,br(r),e??ce.encoder)}s(it,"format");var st=new WeakMap;function br(r){let e=st.get(r);if(e==null){let t=new Map;return st.set(r,t),t}return e}s(br,"baseCache");var Me=class r{static{s(this,"CID")}code;version;multihash;bytes;"/";constructor(e,t,n,i){this.code=t,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}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:t}=this;if(e!==Se)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==In)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:t}=this.multihash,n=le(e,t);return r.createV1(this.code,n)}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 r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Zr(e.multihash,n.multihash)}toString(e){return it(this,e)}toJSON(){return{"/":it(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 t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:i,multihash:o,bytes:a}=t;return new r(n,i,o,a??ot(n,i,o.bytes))}else if(t[Nn]===!0){let{version:n,multihash:i,code:o}=t,a=Jr(i);return r.create(n,o,a)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Se)throw new Error(`Version 0 CID must use dag-pb (code: ${Se}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let i=ot(e,t,n.bytes);return new r(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Se,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,i=F(e.subarray(n,n+t.multihashSize));if(i.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=i.subarray(t.multihashSize-t.digestSize),a=new fe(t.multihashCode,t.digestSize,o,i);return[t.version===0?r.createV0(a):r.createV1(t.codec,a),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=s(()=>{let[b,w]=Ee(e.subarray(t));return t+=w,b},"next"),i=n(),o=Se;if(i===18?(i=0,t=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let a=t,y=n(),c=n(),u=t+c,g=u-a;return{version:i,codec:o,multihashCode:y,digestSize:c,multihashSize:g,size:u}}static parse(e,t){let[n,i]=Tn(e,t),o=r.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return br(o).set(n,e),o}};function Tn(r,e){switch(r[0]){case"Q":{let t=e??R;return[R.prefix,t.decode(`${R.prefix}${r}`)]}case R.prefix:{let t=e??R;return[R.prefix,t.decode(r)]}case ce.prefix:{let t=e??ce;return[ce.prefix,t.decode(r)]}case we.prefix:{let t=e??we;return[we.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}s(Tn,"parseCIDtoBytes");function Dn(r,e,t){let{prefix:n}=t;if(n!==R.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let i=e.get(n);if(i==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return i}s(Dn,"toStringV0");function _n(r,e,t){let{prefix:n}=t,i=e.get(n);if(i==null){let o=t.encode(r);return e.set(n,o),o}else return i}s(_n,"toStringV1");var Se=112,In=18;function ot(r,e,t){let n=ue(r),i=n+ue(e),o=new Uint8Array(i+t.byteLength);return pe(r,o,0),pe(e,o,n),o.set(t,i),o}s(ot,"encodeCID");var Nn=Symbol.for("@ipld/js-cid/CID");var wr={...gr,...ar,...lr,...sr,...or,...cr,...pr,...ur,...fr,...yr},Es={...Kr,...mr};function yt(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}s(yt,"createCodec");var at=yt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),xr=yt("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=be(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Ln={utf8:at,"utf-8":at,hex:wr.base16,latin1:xr,ascii:xr,binary:xr,...wr},Re=Ln;function K(r,e="utf8"){let t=Re[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}s(K,"fromString");function f(r,e="utf8"){let t=Re[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}s(f,"toString");var ht={};v(ht,{AES:()=>m,decryptBytes:()=>gt,importAesKey:()=>me});var V="did:key:z",te="Ed25519",Ce="X25519",kn="X25519",O=32,ct={sign:["sign","verify"],encrypt:["deriveKey","deriveBits"]},Y="RSA-OAEP",$="RSASSA-PKCS1-v1_5",Oe="SHA-256",ze=new Uint8Array([0,245,2]),He=2048,ne="SHA-256",z=8,H="AES-GCM",I=H,q=256,T=12,Er=16,Ge=new Uint8Array([234,1]),Fe=new Uint8Array([237,1]),Pe={RSA:"rsa",Edwards:"ed25519",BLS:"bls12-381"},Ur="rsa-exchange-key",Sr="rsa-write-key",Cr="ecc-exchange",Pr="ecc-write",C=16,Ve=1;var Be=globalThis.crypto,pt=new Error("Invalid key use. Please use 'encryption' or 'signing"),Mn=new Error("Max must be less than 256 and greater than 0");function l(r){return new Uint8Array(r).buffer}s(l,"toArrayBuffer");async function ut(r){let e=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);return new Uint8Array(await Be.subtle.digest("sha-256",e))}s(ut,"sha256");function _(r){let e=K(r,"base64pad");return l(e)}s(_,"base64ToArrBuf");var ie=s((r,e)=>{if(typeof r=="string")return e(r);if(typeof r=="object"&&r.byteLength!==void 0)return new Uint8Array(r).buffer;throw new Error("Improper value. Must be a string, ArrayBuffer, Uint8Array")},"normalizeToBuf");function We(r){return ie(r,_)}s(We,"normalizeBase64ToBuf");var Rn=s(r=>ie(r,e=>l(new TextEncoder().encode(e))),"normalizeUtf8ToBuf");function On(r,e){let t=e===8?new Uint8Array(r.length):new Uint16Array(r.length);for(let n=0,i=r.length;n<i;n++)t[n]=r.charCodeAt(n);return t.buffer}s(On,"strToArrBuf");var zn=s(r=>ie(r,e=>On(e,16)),"normalizeUtf16ToBuf");function J(r,e){return e===8?Rn(r):zn(r)}s(J,"normalizeUnicodeToBuf");function je(r){if(!r.startsWith(V))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=""+r.substring(V.length),t=K(e,"base58btc"),{keyBuffer:n,type:i}=Hn(l(t));return{publicKey:new Uint8Array(n),type:i}}s(je,"didToPublicKey");function Hn(r){if(ge(r,l(ze)))return{keyBuffer:r.slice(ze.byteLength),type:Pe.RSA};if(ge(r,l(Fe)))return{keyBuffer:r.slice(Fe.byteLength),type:Pe.Edwards};if(ge(r,l(Ge)))return{keyBuffer:r.slice(Ge.byteLength),type:Pe.BLS};throw new Error("Unsupported key algorithm. Try using RSA.")}s(Hn,"parseMagicBytes");var Gn={equal:s((r,e)=>{let t=new Uint8Array(r),n=new Uint8Array(e);if(t.length!==n.length)return!1;for(let i=0;i<t.length;i++)if(t[i]!==n[i])return!1;return!0},"equal")};function ge(r,e){return Gn.equal(e,r.slice(0,e.byteLength))}s(ge,"hasPrefix");function S(r){return f(r instanceof ArrayBuffer?new Uint8Array(r):r,"base64pad")}s(S,"toBase64");async function ve(r,e){let t=typeof r=="string"?_(r):l(r);return Be.subtle.importKey("raw",t,{name:e?.alg||I,length:e?.length||q},e?.extractable??!0,["encrypt","decrypt"])}s(ve,"importKey");function Xe(r,{max:e}={max:255}){if(e<1||e>255)throw Mn;let t=new Uint8Array(r);if(e===255)return Be.getRandomValues(t),t.buffer;let n=0,i=e+1,o=Math.floor(256/i)*i,a=new Uint8Array(1);for(;n<t.length;)Be.getRandomValues(a),a[0]<o&&(t[n]=a[0]%i,n++);return t.buffer}s(Xe,"randomBuf");function W(r,e){let t=r instanceof ArrayBuffer?new Uint8Array(r):new Uint8Array(l(r)),n=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(l(e)),i=new Uint8Array(t.length+n.length);return i.set(t),i.set(n,t.length),i.buffer}s(W,"joinBufs");async function Br(r,e,t,n=!1){let i=n;if(!Object.values(re).includes(t))throw new Error("invalid key use");let o=t==="exchange"?Y:$,a=t==="exchange"?["encrypt","decrypt"]:["sign","verify"];return Be.subtle.generateKey({name:o,modulusLength:r,publicExponent:Fn(),hash:{name:e}},i,a)}s(Br,"makeRSAKeypair");function Fn(){return new Uint8Array([1,0,1])}s(Fn,"publicExponent");var L=globalThis.crypto,Ye={keyTypes:{"bls12-381":{magicBytes:new Uint8Array([234,1]),verify:s(()=>{throw new Error("Not implemented")},"verify")},rsa:{magicBytes:new Uint8Array([0,245,2]),verify:lt},ed25519:{magicBytes:new Uint8Array([237,1]),verify:ft}}};async function to({message:r,did:e,signature:t}){let n=Vn(e),i=$e(e).publicKey;if(n==="ed25519")return ft({message:r,publicKey:i,signature:t});if(n==="rsa")return lt({message:r,publicKey:i,signature:t});throw new Error("Unknown key format")}s(to,"verify");function Vn(r){try{let{type:e}=$e(r);return e}catch{return"unknown"}}s(Vn,"getAlgorithm");async function ft({message:r,publicKey:e,signature:t}){let n=r;typeof r=="string"&&(n=K(r,"utf8"));let i=t;typeof t=="string"&&(i=K(t,"base64pad"));let o=e;if(typeof e=="string"&&(o=$e(e).publicKey),o.length!==32)throw new Error(`Invalid Ed25519 public key size: ${o.length} bytes, expected 32`);if(i.length!==64)throw new Error(`Invalid Ed25519 signature size: ${i.length} bytes, expected 64`);let a=await L.subtle.importKey("raw",l(o),{name:"Ed25519"},!1,["verify"]);return L.subtle.verify({name:"Ed25519"},a,l(i),l(n))}s(ft,"ed25519Verify");async function lt({message:r,publicKey:e,signature:t}){let n=e;return typeof e=="string"&&(n=$e(e).publicKey),j.verify(r,t,await L.subtle.importKey("spki",l(n),{name:$,hash:Oe},!1,["verify"]),8)}s(lt,"rsaVerify");var j={verify:s(async function(e,t,n,i=z,o=ne){return L.subtle.verify({name:$},typeof n=="string"?await Te(n,o,"signing"):n,We(t),J(e,i))},"rsaVerify"),sign:s(async function(e,t,n=z){return L.subtle.sign({name:$},t,J(e,n))},"sign"),encrypt:s(async function(e,t,n=z,i=ne){let o;return typeof t=="string"?o=await Te(t,i,"exchange"):o=t instanceof Uint8Array?await Te(l(t),i,"exchange"):t,L.subtle.encrypt({name:Y},o,J(e,n))},"rsaEncrypt"),decrypt:s(async function(e,t){let n=he(t)?t:await Yn(t,["decrypt"]),i;typeof e=="string"?i=K(e,"base64pad"):i=e;let o=await L.subtle.decrypt({name:Y},n,i instanceof Uint8Array?l(i):i);return new Uint8Array(o)},"rsaDecrypt")};async function Te(r,e,t){Wn(t);let n=t==="exchange"?Y:$,i=t==="exchange"?["encrypt"]:["verify"],o=typeof r=="string"?_(Xn(r)):r;return L.subtle.importKey("spki",o,{name:n,hash:{name:e}},!0,i)}s(Te,"rsaImportPublicKey");function Wn(r){jn(r,["signing","exchange"],pt)}s(Wn,"checkValidKeyUse");function jn(r,e,t){if(!e.some(i=>i===r))throw t}s(jn,"checkValid");function Xn(r){return r.replace(`-----BEGIN PUBLIC KEY-----
|
|
1
|
+
"use strict";(()=>{var Gr=Object.defineProperty;var s=(r,e)=>Gr(r,"name",{value:e,configurable:!0});var C=(r,e)=>{for(var t in e)Gr(r,t,{get:e[t],enumerable:!0})};var Fr=(n=>(n[n.B1024=1024]="B1024",n[n.B2048=2048]="B2048",n[n.B4096=4096]="B4096",n))(Fr||{}),Vr=(n=>(n[n.B128=128]="B128",n[n.B192=192]="B192",n[n.B256=256]="B256",n))(Vr||{}),Wr=(t=>(t.ECC="ecc",t.RSA="rsa",t))(Wr||{}),rr=(i=>(i.SHA_1="SHA-1",i.SHA_256="SHA-256",i.SHA_384="SHA-384",i.SHA_512="SHA-512",i))(rr||{}),tr=(i=>(i.P_256="P-256",i.P_384="P-384",i.P_521="P-521",i.X25519="X25519",i))(tr||{}),ie=(n=>(n.Sign="signing",n.Exchange="exchange",n.Write="write",n))(ie||{}),nr=(t=>(t[t.B8=8]="B8",t[t.B16=16]="B16",t))(nr||{});var Ct={};C(Ct,{AES_GCM:()=>G,AES_GCM_TAG_LENGTH:()=>vr,BASE58_DID_PREFIX:()=>W,BLS_DID_PREFIX:()=>je,DEFAULT_CHAR_SIZE:()=>H,DEFAULT_ECC_EXCHANGE:()=>Dr,DEFAULT_ECC_EXCHANGE_CURVE:()=>Vn,DEFAULT_ECC_WRITE:()=>_r,DEFAULT_HASH_ALGORITHM:()=>ae,DEFAULT_RSA_EXCHANGE:()=>Br,DEFAULT_RSA_SIZE:()=>We,DEFAULT_RSA_WRITE:()=>Tr,DEFAULT_SYMM_ALGORITHM:()=>I,DEFAULT_SYMM_LENGTH:()=>Z,ECC_EXCHANGE_ALGORITHM:()=>De,ECC_WRITE_ALGORITHM:()=>oe,EDWARDS_DID_PREFIX:()=>Xe,IV_LENGTH:()=>P,KEY_TYPE:()=>_e,KEY_USE:()=>ht,RSA_ALGORITHM:()=>q,RSA_DID_PREFIX:()=>Ve,RSA_HASHING_ALGORITHM:()=>Fe,RSA_SIGN_ALGORITHM:()=>J,RsaKeys:()=>pe,SALT_LENGTH:()=>U,WRAP_FORMAT_VERSION:()=>Ye,X25519_PUBLIC_KEY_LENGTH:()=>z,encrypt:()=>ui,encryptKeyTo:()=>Ue,encryptTo:()=>St,getPublicKeyAsArrayBuffer:()=>ee,getPublicKeyAsUint8Array:()=>Lr,publicKeyToDid:()=>ke,verify:()=>pi});function fe(r=0){return new Uint8Array(r)}s(fe,"allocUnsafe");function _t(r){return r?.buffer instanceof ArrayBuffer}s(_t,"isByteArrayWithArrayBuffer");function ir(r){if(_t(r))return r;let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}s(ir,"asUint8Array");function sr(r,e){e==null&&(e=r.reduce((i,o)=>i+o.length,0));let t=fe(e),n=0;for(let i of r)t.set(i,n),n+=i.length;return ir(t)}s(sr,"concat");var pr={};C(pr,{base10:()=>zt});var ki=new Uint8Array(0);function Xr(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}s(Xr,"equals");function k(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return se(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return se(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}s(k,"coerce");function Yr(r){let e=new Uint8Array(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}s(Yr,"fromString");var jr=4096;function $r(r){let e=r.length;if(e<=jr)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.subarray(n,n+=jr));return t}s($r,"toString");function It(r){return r?.buffer instanceof ArrayBuffer}s(It,"isByteArrayWithArrayBuffer");function se(r){return It(r)?r:r.slice()}s(se,"toArrayBufferBackedArray");function Nt(r,e,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),i=0;i<n.length;i++)n[i]=255;for(var o=0;o<r.length;o++){var a=r.charAt(o),y=a.charCodeAt(0);if(n[y]!==255)throw new TypeError(a+" is ambiguous");if(n[y]=o,t){var c=a.toLowerCase().charCodeAt(0),p=a.toUpperCase().charCodeAt(0);c!==y&&(n[c]=o),p!==y&&(n[p]=o)}}var f=r.length,A=r.charAt(0),w=Math.log(f)/Math.log(256),R=Math.log(256)/Math.log(f);function N(u){if(u instanceof Uint8Array||(ArrayBuffer.isView(u)?u=new Uint8Array(u.buffer,u.byteOffset,u.byteLength):Array.isArray(u)&&(u=Uint8Array.from(u))),!(u instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(u.length===0)return"";for(var h=0,E=0,S=0,v=u.length;S!==v&&u[S]===0;)S++,h++;for(var L=(v-S)*R+1>>>0,Y=new Uint8Array(L);S!==v;){for(var B=u[S],ne=0,V=L-1;(B!==0||ne<E)&&V!==-1;V--,ne++)B+=256*Y[V]>>>0,Y[V]=B%f>>>0,B=B/f>>>0;if(B!==0)throw new Error("Non-zero carry");E=ne,S++}for(var _=L-E;_!==L&&Y[_]===0;)_++;for(var Se=A.repeat(h);_<L;++_)Se+=r.charAt(Y[_]);return Se}s(N,"encode");function D(u){if(typeof u!="string")throw new TypeError("Expected String");if(u.length===0)return new Uint8Array;var h=0;if(u[h]!==" "){for(var E=0,S=0;u[h]===A;)E++,h++;for(var v=(u.length-h)*w+1>>>0,L=new Uint8Array(v);u[h];){var Y=u.charCodeAt(h);if(Y>255)return;var B=n[Y];if(B===255)return;for(var ne=0,V=v-1;(B!==0||ne<S)&&V!==-1;V--,ne++)B+=f*L[V]>>>0,L[V]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");S=ne,h++}if(u[h]!==" "){for(var _=v-S;_!==v&&L[_]===0;)_++;for(var Se=new Uint8Array(E+(v-_)),Dt=E;_!==v;)Se[Dt++]=L[_++];return Se}}}s(D,"decodeUnsafe");function F(u){var h=D(u);if(h)return h;throw new Error(`Non-${e} character`)}return s(F,"decode"),{encode:N,decodeUnsafe:D,decode:F}}s(Nt,"base");var Lt=Nt,kt=Lt,Jr=kt;var or=class{static{s(this,"Encoder")}name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},ar=class{static{s(this,"Decoder")}name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let i=t.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,this.baseDecode=n}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 Zr(this,e)}},yr=class{static{s(this,"ComposedDecoder")}decoders;constructor(e){this.decoders=e}or(e){return Zr(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Zr(r,e){return new yr({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}s(Zr,"or");var cr=class{static{s(this,"Codec")}name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,i){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new or(e,t,n),this.decoder=new ar(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function le({name:r,prefix:e,encode:t,decode:n}){return new cr(r,e,t,n)}s(le,"from");function $({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:i,decode:o}=Jr(t,r,n);return le({prefix:e,name:r,encode:i,decode:s(a=>k(o(a)),"decode")})}s($,"baseX");function Mt(r,e,t,n){let i=r.length;for(;r[i-1]==="=";)--i;let o=new Uint8Array(i*t/8|0),a=0,y=0,c=0;for(let p=0;p<i;++p){let f=e[r[p]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);y=y<<t|f,a+=t,a>=8&&(a-=8,o[c++]=255&y>>a)}if(a>=t||(255&y<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return o}s(Mt,"decode");function Rt(r,e,t){let n=e[e.length-1]==="=",i=(1<<t)-1,o="",a=0,y=0;for(let c=0;c<r.length;++c)for(y=y<<8|r[c],a+=8;a>t;)a-=t,o+=e[i&y>>a];if(a!==0&&(o+=e[i&y<<t-a]),n)for(;(o.length*t&7)!==0;)o+="=";return o}s(Rt,"encode");function Ot(r,e){let t={};for(let n=0;n<r.length;++n)if(r[n]!=="="&&(t[r[n]]=n,e)){let i=r[n].toLowerCase(),o=r[n].toUpperCase();i!==r[n]&&(t[i]=n),o!==r[n]&&(t[o]=n)}return t}s(Ot,"createAlphabetIdx");function K({name:r,prefix:e,bitsPerChar:t,alphabet:n,caseInsensitive:i=!1}){let o=Ot(n,i);return le({prefix:e,name:r,encode(a){return Rt(a,n,t)},decode(a){return Mt(a,o,t,r)}})}s(K,"rfc4648");var zt=$({prefix:"9",name:"base10",alphabet:"0123456789"});var ur={};C(ur,{base16:()=>Ht,base16upper:()=>Gt});var Ht=K({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Gt=K({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var fr={};C(fr,{base2:()=>Ft});var Ft=K({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var lr={};C(lr,{base256emoji:()=>Yt});var Qr=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}"),Vt=Qr.reduce((r,e,t)=>(r[t]=e,r),[]),Wt=Qr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function jt(r){return r.reduce((e,t)=>(e+=Vt[t],e),"")}s(jt,"encode");function Xt(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let i=Wt[n];if(i==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(i)}return new Uint8Array(e)}s(Xt,"decode");var Yt=le({prefix:"\u{1F680}",name:"base256emoji",encode:jt,decode:Xt});var gr={};C(gr,{base32:()=>ge,base32hex:()=>Zt,base32hexpad:()=>en,base32hexpadupper:()=>rn,base32hexupper:()=>Qt,base32pad:()=>qt,base32padupper:()=>Jt,base32upper:()=>$t,base32z:()=>tn});var ge=K({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),$t=K({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),qt=K({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Jt=K({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Zt=K({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Qt=K({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),en=K({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),rn=K({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),tn=K({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var hr={};C(hr,{base36:()=>Ce,base36upper:()=>nn});var Ce=$({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),nn=$({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var mr={};C(mr,{base58btc:()=>O,base58flickr:()=>sn});var O=$({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),sn=$({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var dr={};C(dr,{base64:()=>on,base64pad:()=>an,base64url:()=>yn,base64urlpad:()=>cn});var on=K({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),an=K({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),yn=K({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),cn=K({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ar={};C(Ar,{base8:()=>pn});var pn=K({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Kr={};C(Kr,{identity:()=>un});var un=le({prefix:"\0",name:"identity",encode:s(r=>$r(k(r)),"encode"),decode:s(r=>k(Yr(r)),"decode")});var ns=new TextEncoder,is=new TextDecoder;var wr={};C(wr,{identity:()=>Nn});var gn=tt,et=128,hn=127,mn=~hn,dn=Math.pow(2,31);function tt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=dn;)e[t++]=r&255|et,r/=128;for(;r&mn;)e[t++]=r&255|et,r>>>=7;return e[t]=r|0,tt.bytes=t-n+1,e}s(tt,"encode");var An=br,Kn=128,rt=127;function br(r,n){var t=0,n=n||0,i=0,o=n,a,y=r.length;do{if(o>=y)throw br.bytes=0,new RangeError("Could not decode varint");a=r[o++],t+=i<28?(a&rt)<<i:(a&rt)*Math.pow(2,i),i+=7}while(a>=Kn);return br.bytes=o-n,t}s(br,"read");var bn=Math.pow(2,7),wn=Math.pow(2,14),xn=Math.pow(2,21),En=Math.pow(2,28),Un=Math.pow(2,35),Sn=Math.pow(2,42),Cn=Math.pow(2,49),Pn=Math.pow(2,56),vn=Math.pow(2,63),Bn=s(function(r){return r<bn?1:r<wn?2:r<xn?3:r<En?4:r<Un?5:r<Sn?6:r<Cn?7:r<Pn?8:r<vn?9:10},"length"),Tn={encode:gn,decode:An,encodingLength:Bn},Dn=Tn,Pe=Dn;function ve(r,e=0){let t=Pe.decode(r,e),n=Pe.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&r[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[t,n]}s(ve,"decode");function he(r,e,t=0){return Pe.encode(r,e,t),e}s(he,"encodeTo");function me(r){return Pe.encodingLength(r)}s(me,"encodingLength");function Ae(r,e){let t=e.byteLength,n=me(r),i=n+me(t),o=new Uint8Array(i+t);return he(r,o,0),he(t,o,n),o.set(e,i),new de(r,t,e,o)}s(Ae,"create");function nt(r){let e=k(r),[t,n]=ve(e),[i,o]=ve(e.subarray(n)),a=e.subarray(n+o);if(a.byteLength!==i)throw new Error("Incorrect length");return new de(t,i,a,e)}s(nt,"decode");function it(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Xr(r.bytes,t.bytes)}}s(it,"equals");var de=class{static{s(this,"Digest")}code;size;digest;bytes;constructor(e,t,n,i){this.code=e,this.size=t,this.digest=se(n),this.bytes=se(i)}};var st=0,_n="identity",ot=k;function In(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return Ae(st,ot(r))}s(In,"digest");var Nn={code:st,name:_n,encode:ot,digest:In};var Ur={};C(Ur,{sha256:()=>kn,sha512:()=>Mn});var Ln=20;function Er({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:i}){return new xr(r,e,t,n,i)}s(Er,"from");var xr=class{static{s(this,"Hasher")}name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,i,o){this.name=e,this.code=t,this.encode=n,this.minDigestLength=i??Ln,this.maxDigestLength=o}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?at(n,this.code,t?.truncate):n.then(i=>at(i,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function at(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return Ae(e,r)}s(at,"createDigest");function ct(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}s(ct,"sha");var kn=Er({name:"sha2-256",code:18,encode:ct("SHA-256")}),Mn=Er({name:"sha2-512",code:19,encode:ct("SHA-512")});function pt(r,e){let{bytes:t,version:n}=r;return n===0?On(t,Sr(r),e??O.encoder):zn(t,Sr(r),e??ge.encoder)}s(pt,"format");var ut=new WeakMap;function Sr(r){let e=ut.get(r);if(e==null){let t=new Map;return ut.set(r,t),t}return e}s(Sr,"baseCache");var He=class r{static{s(this,"CID")}code;version;multihash;bytes;"/";constructor(e,t,n,i){this.code=t,this.version=e,this.multihash=n,this.bytes=se(i),this["/"]=this.bytes}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:t}=this;if(e!==Te)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Hn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:t}=this.multihash,n=Ae(e,t);return r.createV1(this.code,n)}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 r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&it(e.multihash,n.multihash)}toString(e){return pt(this,e)}toJSON(){return{"/":pt(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 t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:i,multihash:o,bytes:a}=t;return new r(n,i,o,a??ft(n,i,o.bytes))}else if(t[Gn]===!0){let{version:n,multihash:i,code:o}=t,a=nt(i);return r.create(n,o,a)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Te)throw new Error(`Version 0 CID must use dag-pb (code: ${Te}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let i=ft(e,t,n.bytes);return new r(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Te,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,i=k(e.subarray(n,n+t.multihashSize));if(i.byteLength!==t.multihashSize)throw new Error("Incorrect length");let o=i.subarray(t.multihashSize-t.digestSize),a=new de(t.multihashCode,t.digestSize,o,i);return[t.version===0?r.createV0(a):r.createV1(t.codec,a),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=s(()=>{let[A,w]=ve(e.subarray(t));return t+=w,A},"next"),i=n(),o=Te;if(i===18)i=0,t=0;else if(i===1)o=n();else throw i===0?new RangeError("Invalid CID version, v0 is always implicit"):new RangeError(`Invalid CID version ${i}`);let a=t,y=n(),c=n(),p=t+c,f=p-a;return{version:i,codec:o,multihashCode:y,digestSize:c,multihashSize:f,size:p}}static parse(e,t){let[n,i]=Rn(e,t),o=r.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Sr(o).set(n,e),o}};function Rn(r,e){switch(r[0]){case"Q":{let t=e??O;return[O.prefix,t.decode(`${O.prefix}${r}`)]}case O.prefix:{let t=e??O;return[O.prefix,t.decode(r)]}case ge.prefix:{let t=e??ge;return[ge.prefix,t.decode(r)]}case Ce.prefix:{let t=e??Ce;return[Ce.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}s(Rn,"parseCIDtoBytes");function On(r,e,t){let{prefix:n}=t;if(n!==O.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let i=e.get(n);if(i==null){let o=t.encode(r).slice(1);return e.set(n,o),o}else return i}s(On,"toStringV0");function zn(r,e,t){let{prefix:n}=t,i=e.get(n);if(i==null){let o=t.encode(r);return e.set(n,o),o}else return i}s(zn,"toStringV1");var Te=112,Hn=18;function ft(r,e,t){let n=me(r),i=n+me(e),o=new Uint8Array(i+t.byteLength);return he(r,o,0),he(e,o,n),o.set(t,i),o}s(ft,"encodeCID");var Gn=Symbol.for("@ipld/js-cid/CID");var Cr={...Kr,...fr,...Ar,...pr,...ur,...gr,...hr,...mr,...dr,...lr},Ls={...Ur,...wr};function gt(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}s(gt,"createCodec");var lt=gt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Pr=gt("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=fe(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Fn={utf8:lt,"utf-8":lt,hex:Cr.base16,latin1:Pr,ascii:Pr,binary:Pr,...Cr},Ge=Fn;function b(r,e="utf8"){let t=Ge[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}s(b,"fromString");function l(r,e="utf8"){let t=Ge[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}s(l,"toString");var wt={};C(wt,{AES:()=>m,decryptBytes:()=>bt,importAesKey:()=>we});var W="did:key:z",oe="Ed25519",De="X25519",Vn="X25519",z=32,ht={sign:["sign","verify"],encrypt:["deriveKey","deriveBits"]},q="RSA-OAEP",J="RSASSA-PKCS1-v1_5",Fe="SHA-256",Ve=new Uint8Array([0,245,2]),We=2048,ae="SHA-256",H=8,G="AES-GCM",I=G,Z=256,P=12,vr=16,je=new Uint8Array([234,1]),Xe=new Uint8Array([237,1]),_e={RSA:"rsa",Edwards:"ed25519",BLS:"bls12-381"},Br="rsa-exchange-key",Tr="rsa-write-key",Dr="ecc-exchange",_r="ecc-write",U=16,Ye=1;var Ie=globalThis.crypto,mt=new Error("Invalid key use. Please use 'encryption' or 'signing"),Wn=new Error("Max must be less than 256 and greater than 0");function g(r){return new Uint8Array(r).buffer}s(g,"toArrayBuffer");async function dt(r){let e=r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength);return new Uint8Array(await Ie.subtle.digest("sha-256",e))}s(dt,"sha256");function T(r){let e=b(r,"base64pad");return g(e)}s(T,"base64ToArrBuf");var ye=s((r,e)=>{if(typeof r=="string")return e(r);if(typeof r=="object"&&r.byteLength!==void 0)return new Uint8Array(r).buffer;throw new Error("Improper value. Must be a string, ArrayBuffer, Uint8Array")},"normalizeToBuf");function $e(r){return ye(r,T)}s($e,"normalizeBase64ToBuf");var jn=s(r=>ye(r,e=>g(new TextEncoder().encode(e))),"normalizeUtf8ToBuf");function Xn(r,e){let t=e===8?new Uint8Array(r.length):new Uint16Array(r.length);for(let n=0,i=r.length;n<i;n++)t[n]=r.charCodeAt(n);return t.buffer}s(Xn,"strToArrBuf");var Yn=s(r=>ye(r,e=>Xn(e,16)),"normalizeUtf16ToBuf");function Q(r,e){return e===8?jn(r):Yn(r)}s(Q,"normalizeUnicodeToBuf");function qe(r){if(!r.startsWith(W))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=""+r.substring(W.length),t=b(e,"base58btc"),{keyBuffer:n,type:i}=$n(g(t));return{publicKey:new Uint8Array(n),type:i}}s(qe,"didToPublicKey");function $n(r){if(Ke(r,g(Ve)))return{keyBuffer:r.slice(Ve.byteLength),type:_e.RSA};if(Ke(r,g(Xe)))return{keyBuffer:r.slice(Xe.byteLength),type:_e.Edwards};if(Ke(r,g(je)))return{keyBuffer:r.slice(je.byteLength),type:_e.BLS};throw new Error("Unsupported key algorithm. Try using RSA.")}s($n,"parseMagicBytes");var qn={equal:s((r,e)=>{let t=new Uint8Array(r),n=new Uint8Array(e);if(t.length!==n.length)return!1;for(let i=0;i<t.length;i++)if(t[i]!==n[i])return!1;return!0},"equal")};function Ke(r,e){return qn.equal(e,r.slice(0,e.byteLength))}s(Ke,"hasPrefix");function x(r){return l(r instanceof ArrayBuffer?new Uint8Array(r):r,"base64pad")}s(x,"toBase64");async function Ne(r,e){let t=typeof r=="string"?T(r):g(r);return Ie.subtle.importKey("raw",t,{name:e?.alg||I,length:e?.length||Z},e?.extractable??!0,["encrypt","decrypt"])}s(Ne,"importKey");function Je(r,{max:e}={max:255}){if(e<1||e>255)throw Wn;let t=new Uint8Array(r);if(e===255)return Ie.getRandomValues(t),t.buffer;let n=0,i=e+1,o=Math.floor(256/i)*i,a=new Uint8Array(1);for(;n<t.length;)Ie.getRandomValues(a),a[0]<o&&(t[n]=a[0]%i,n++);return t.buffer}s(Je,"randomBuf");function j(r,e){let t=r instanceof ArrayBuffer?new Uint8Array(r):new Uint8Array(g(r)),n=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(g(e)),i=new Uint8Array(t.length+n.length);return i.set(t),i.set(n,t.length),i.buffer}s(j,"joinBufs");async function Ir(r,e,t,n=!1){let i=n;if(!Object.values(ie).includes(t))throw new Error("invalid key use");let o=t==="exchange"?q:J,a=t==="exchange"?["encrypt","decrypt"]:["sign","verify"];return Ie.subtle.generateKey({name:o,modulusLength:r,publicExponent:Jn(),hash:{name:e}},i,a)}s(Ir,"makeRSAKeypair");function Jn(){return new Uint8Array([1,0,1])}s(Jn,"publicExponent");var M=globalThis.crypto,Ze={keyTypes:{"bls12-381":{magicBytes:new Uint8Array([234,1]),verify:s(()=>{throw new Error("Not implemented")},"verify")},rsa:{magicBytes:new Uint8Array([0,245,2]),verify:Kt},ed25519:{magicBytes:new Uint8Array([237,1]),verify:At}}};async function wo({message:r,did:e,signature:t}){let n=Zn(e),i=Qe(e).publicKey;if(n==="ed25519")return At({message:r,publicKey:i,signature:t});if(n==="rsa")return Kt({message:r,publicKey:i,signature:t});throw new Error("Unknown key format")}s(wo,"verify");function Zn(r){try{let{type:e}=Qe(r);return e}catch{return"unknown"}}s(Zn,"getAlgorithm");async function At({message:r,publicKey:e,signature:t}){let n=r;typeof r=="string"&&(n=b(r,"utf8"));let i=t;typeof t=="string"&&(i=b(t,"base64pad"));let o=e;if(typeof e=="string"&&(o=Qe(e).publicKey),o.length!==32)throw new Error(`Invalid Ed25519 public key size: ${o.length} bytes, expected 32`);if(i.length!==64)throw new Error(`Invalid Ed25519 signature size: ${i.length} bytes, expected 64`);let a=await M.subtle.importKey("raw",g(o),{name:"Ed25519"},!1,["verify"]);return M.subtle.verify({name:"Ed25519"},a,g(i),g(n))}s(At,"ed25519Verify");async function Kt({message:r,publicKey:e,signature:t}){let n=e;return typeof e=="string"&&(n=Qe(e).publicKey),X.verify(r,t,await M.subtle.importKey("spki",g(n),{name:J,hash:Fe},!1,["verify"]),8)}s(Kt,"rsaVerify");var X={verify:s(async function(e,t,n,i=H,o=ae){return M.subtle.verify({name:J},typeof n=="string"?await Le(n,o,"signing"):n,$e(t),Q(e,i))},"rsaVerify"),sign:s(async function(e,t,n=H){return M.subtle.sign({name:J},t,Q(e,n))},"sign"),encrypt:s(async function(e,t,n=H,i=ae){let o;return typeof t=="string"?o=await Le(t,i,"exchange"):o=t instanceof Uint8Array?await Le(g(t),i,"exchange"):t,M.subtle.encrypt({name:q},o,Q(e,n))},"rsaEncrypt"),decrypt:s(async function(e,t){let n=be(t)?t:await ti(t,["decrypt"]),i;typeof e=="string"?i=b(e,"base64pad"):i=e;let o=await M.subtle.decrypt({name:q},n,i instanceof Uint8Array?g(i):i);return new Uint8Array(o)},"rsaDecrypt")};async function Le(r,e,t){Qn(t);let n=t==="exchange"?q:J,i=t==="exchange"?["encrypt"]:["verify"],o=typeof r=="string"?T(ri(r)):r;return M.subtle.importKey("spki",o,{name:n,hash:{name:e}},!0,i)}s(Le,"rsaImportPublicKey");function Qn(r){ei(r,["signing","exchange"],mt)}s(Qn,"checkValidKeyUse");function ei(r,e,t){if(!e.some(i=>i===r))throw t}s(ei,"checkValid");function ri(r){return r.replace(`-----BEGIN PUBLIC KEY-----
|
|
2
2
|
`,"").replace(`
|
|
3
|
-
-----END PUBLIC KEY-----`,"")}s(Xn,"stripKeyHeader");function he(r){return typeof CryptoKey<"u"?r instanceof CryptoKey:vr(r,"algorithm")&&vr(r,"extractable")&&vr(r,"type")}s(he,"isCryptoKey");function vr(r,e){return typeof r=="object"&&r!=null&&e in r}s(vr,"hasProp");function Yn(r,e){return L.subtle.importKey("spki",r instanceof Uint8Array?l(r):r,{name:Y,hash:Oe},!1,e)}s(Yn,"importRsaKey");async function De(r,e="rsa"){let t;if(r instanceof CryptoKey){e=r.algorithm.name.includes("RSA")?"rsa":"ed25519";let o=e==="ed25519"?"raw":"spki",a=await L.subtle.exportKey(o,r);t=new Uint8Array(a)}else t=r;let n=Ye.keyTypes[e]?.magicBytes;if(!n)throw new Error(`Key type '${e}' not supported, available types: ${Object.keys(Ye.keyTypes).join(", ")}`);let i=er([n,t]);return V+f(i,"base58btc")}s(De,"publicKeyToDid");function no(r){let e=r.substring(V.length),t=K(e,"base58btc"),n=Object.entries(Ye.keyTypes).find(([o,a])=>ge(l(t),l(a.magicBytes)));if(!n)throw new Error("Invalid key type");let i=n[0];if(i!=="ed25519"&&i!=="rsa")throw new Error(`Unsupported key type: ${i}`);return i}s(no,"keyTypeFromDid");async function Z(r){return r instanceof CryptoKey?await L.subtle.exportKey("spki",r):await L.subtle.exportKey("spki",r.publicKey)}s(Z,"getPublicKeyAsArrayBuffer");async function Tr(r){let e=await Z(r);return new Uint8Array(e)}s(Tr,"getPublicKeyAsUint8Array");function $e(r){if(!r.startsWith(V))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=r.substring(V.length),t=K(e,"base58btc"),n=Object.entries(Ye.keyTypes).find(([o,a])=>ge(l(t),l(a.magicBytes)));if(!n)throw new Error("Unsupported key algorithm.");let i=t.slice(n[1].magicBytes.length);return n[0]==="ed25519"&&i.length===44?{publicKey:i.slice(-32),type:n[0]}:{publicKey:i,type:n[0]}}s($e,"didToPublicKey");var se=globalThis.crypto,m={create(r={alg:I,length:q}){let e=r.length||q,t=r.alg||I,n=r.extractable??!0;return se.subtle.generateKey({name:t,length:e},n,["encrypt","decrypt"])},export:Object.assign(async r=>{let e=await se.subtle.exportKey("raw",r);return new Uint8Array(e)},{asString:s(async(r,e)=>{let t=await m.export(r);return e?f(t,e):S(t)},"asString")}),import(r,e){return me(typeof r=="string"?_(r):r,void 0,e)},async exportAsString(r){let e=await m.export(r);return S(e)},encrypt:$n,async decrypt(r,e,t){let n=he(e)?e:await me(e),i=t?await se.subtle.decrypt({name:H,iv:l(t)},n,typeof r=="string"?l(K(r,"base64pad")):r instanceof Uint8Array?l(r):r):await gt(r,n);return new Uint8Array(i)}};function me(r,e,t=!0){return se.subtle.importKey("raw",r instanceof Uint8Array?l(r):r,{name:H,length:e||256},t,["encrypt","decrypt"])}s(me,"importAesKey");async function $n(r,e,t,n){let i=he(e)?e:await me(e),o=n?await se.subtle.encrypt({name:H,iv:l(n)},i,r instanceof ArrayBuffer?r:l(typeof r=="string"?K(r):r)):await qn(r,i);return t&&t==="arraybuffer"?o:new Uint8Array(o)}s($n,"encrypt");async function qn(r,e,t){let n=J(r,t?.charsize??z),i=typeof e=="string"?await ve(e,t):e,o=t?.iv||Xe(T),a=await se.subtle.encrypt({name:H,iv:o},i,n);return W(o,a)}s(qn,"encryptBytes");async function gt(r,e,t){let n=We(r),i=typeof e=="string"?await ve(e,t):e,o=n.slice(0,T),a=n.slice(T);return await se.subtle.decrypt({name:I,iv:o},i,a)}s(gt,"decryptBytes");function qe(r){return new Promise((e,t)=>{r.oncomplete=r.onsuccess=()=>e(r.result),r.onabort=r.onerror=()=>t(r.error)})}s(qe,"promisifyRequest");function Jn(r,e){let t,n=s(()=>{if(t)return t;let i=indexedDB.open(r);return i.onupgradeneeded=()=>i.result.createObjectStore(e),t=qe(i),t.then(o=>{o.onclose=()=>t=void 0},()=>{t=void 0}),t},"getDB");return(i,o)=>n().then(a=>o(a.transaction(e,i).objectStore(e)))}s(Jn,"createStore");var Dr;function _r(){return Dr||(Dr=Jn("keyval-store","keyval")),Dr}s(_r,"defaultGetStore");function _e(r,e=_r()){return e("readonly",t=>qe(t.get(r)))}s(_e,"get");function Ir(r,e,t=_r()){return t("readwrite",n=>(n.put(e,r),qe(n.transaction)))}s(Ir,"set");function Nr(r,e=_r()){return e("readwrite",t=>(r.forEach(n=>t.delete(n)),qe(t.transaction)))}s(Nr,"delMany");var ho=new Error("Key does not exist. Make sure you properly instantiated the keystore."),mo=new Error("Retrieved a symmetric key when an asymmetric keypair was expected. Please use a different key name."),Ao=new Error("Retrieved an asymmetric keypair when an symmetric key was expected. Please use a different key name."),Ko=new Error("ECC is not enabled for this browser. Please use RSA instead."),bo=new Error("Cryptosystem not supported. Please use ECC or RSA"),Zn=new Error("Invalid key use. Please use 'exchange' or 'write'"),wo=new Error("Max must be less than 256 and greater than 0"),de=class extends Error{static{s(this,"KeysDeletedError")}constructor(e){super(e||"These keys were deleted"),this.name="KeysDeletedError"}};function mt(r){Qn(r,["exchange","write","signing"],Zn)}s(mt,"checkValidKeyUse");function Qn(r,e,t){if(!e.some(i=>i===r))throw t}s(Qn,"checkValid");var Ae=class r{static{s(this,"AbstractKeys")}DID;hasPersisted;isSessionOnly;destroyed;exchangeKeyName;writeKeyName;static EXCHANGE_KEY_NAME;static WRITE_KEY_NAME;static _instance;_exchangeKey;_writeKey;constructor(e){let{keys:t}=e,n=this.constructor;this.DID=e.did,this._exchangeKey=t.exchange,this._writeKey=t.write,this.hasPersisted=e.hasPersisted,this.isSessionOnly=!!e.isSessionOnly,this.destroyed=!1,this.exchangeKeyName=e.exchangeKeyName||n.EXCHANGE_KEY_NAME,this.writeKeyName=e.writeKeyName||n.WRITE_KEY_NAME}get exchangeKey(){if(this.destroyed||!this._exchangeKey)throw new de;return this._exchangeKey}get writeKey(){if(this.destroyed||!this._writeKey)throw new de;return this._writeKey}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:s(async t=>{let n=await Z(this.writeKey),i=new Uint8Array(n);return t?f(i,t):S(i)},"asString")})}get publicExchangeKey(){let e=this.exchangeKey.publicKey;return Object.assign(e,{asString:s(async t=>{let n=await Z(this.exchangeKey),i=new Uint8Array(n);return t?f(i,t):S(i)},"asString")})}get privateWriteKey(){return this.writeKey.privateKey}get privateExchangeKey(){return this.exchangeKey.privateKey}get deviceName(){return r.deviceName(this.DID)}static deviceName(e){return ei(e)}async persist(){if(this.destroyed)throw new de;this.isSessionOnly||(await Promise.all([Ir(this.exchangeKeyName,this.exchangeKey),Ir(this.writeKeyName,this.writeKey)]),this.hasPersisted=!0)}async delete(){let e=this.exchangeKeyName,t=this.writeKeyName;await Nr([e,t]),this.constructor._invalidate(e,t),this._destroy()}_destroy(){this.destroyed=!0,this.hasPersisted=!1,this._exchangeKey=null,this._writeKey=null}static _invalidate(e,t){let n=this._instance;n&&n.exchangeKeyName===e&&n.writeKeyName===t&&(n._destroy(),this._instance=null)}static async delete(e={}){let t=e.encryptionKeyName||this.EXCHANGE_KEY_NAME,n=e.writeKeyName||this.WRITE_KEY_NAME;await Nr([t,n]),this._invalidate(t,n)}async getDeviceName(){return r.deviceName(this.DID)}static _createExchangeKeys(e){throw new Error("The child should implement this")}static _createWriteKeys(e){throw new Error("The child should implement this")}static _keyNames(e){return e?{exchangeKeyName:`${e}.${this.EXCHANGE_KEY_NAME}`,writeKeyName:`${e}.${this.WRITE_KEY_NAME}`}:{exchangeKeyName:this.EXCHANGE_KEY_NAME,writeKeyName:this.WRITE_KEY_NAME}}static async create(e,t,n){let i=n?.exchangeKeys||await this._createExchangeKeys(t),o=n?.writeKeys||await this._createWriteKeys(t),a=await Z(o),y=await De(new Uint8Array(a),this.TYPE==="ecc"?"ed25519":"rsa"),{exchangeKeyName:c,writeKeyName:u}=this._keyNames(n?.dbKey),g=new this({keys:{exchange:i,write:o},did:y,hasPersisted:!1,isSessionOnly:!!e,exchangeKeyName:c,writeKeyName:u});return this._instance=g,g}static async exist(e={}){let t=await _e(e.writeKeyName||this.WRITE_KEY_NAME),n=await _e(e.encryptionKeyName||this.EXCHANGE_KEY_NAME);return!(!t||!n)}static async load(e={session:!1}){let t=e.persist!==!1,n=this._keyNames(e.dbKey),i=e.encryptionKeyName||n.exchangeKeyName,o=e.writeKeyName||n.writeKeyName,a=this._instance;if(a&&!a.destroyed&&a.exchangeKeyName===i&&a.writeKeyName===o)return t&&!a.hasPersisted&&await a.persist(),a;let y=!0,c=await _e(i),u=await _e(o);c||(y=!1,c=await this._createExchangeKeys(e.extractable)),u||(y=!1,u=await this._createWriteKeys(e.extractable));let g=await Z(u),b=await De(new Uint8Array(g),this.TYPE==="ecc"?"ed25519":"rsa"),w=new this({keys:{exchange:c,write:u},did:b,hasPersisted:y,isSessionOnly:!!e.session,exchangeKeyName:i,writeKeyName:o});return this._instance=w,t&&!y&&await w.persist(),w}};async function dt(r,e){let{content:t,publicKey:n}=r,i=e||await m.create(),o=await m.encrypt(typeof t=="string"?K(t):t,typeof i=="string"?await m.import(i):i),a=await Lr({key:i,publicKey:n});return W(a,o)}s(dt,"encryptTo");dt.asString=async function(r,e){let t=await dt(r,e);return f(new Uint8Array(t),"base64pad")};async function Lr({key:r,publicKey:e},t){let n;r instanceof CryptoKey?n=await m.export(r):n=r;let i=await j.encrypt(n,e);return t&&t==="arraybuffer"?i:new Uint8Array(i)}s(Lr,"encryptKeyTo");Lr.asString=async function({key:r,publicKey:e},t){let n=await Lr({key:r,publicKey:e});return t?f(n,t):S(n)};async function ei(r){let e=await ut(new TextEncoder().encode(r.normalize("NFD")));return f(e,"base32").slice(0,32)}s(ei,"getDeviceName");var kr=globalThis.crypto;function At(r){return new Uint8Array(r).buffer}s(At,"toArrayBuffer");function ri(r){return r.algorithm.modulusLength/8}s(ri,"rsaCiphertextByteLength");var oe=class extends Ae{static{s(this,"RsaKeys")}static TYPE="rsa";static INFO="keys";static EXCHANGE_KEY_NAME=Ur;static WRITE_KEY_NAME=Sr;static async create(e,t,n){return await super.create(e,t,n)}static async load(e={session:!1}){return super.load(e)}static async _createExchangeKeys(e=!1){return await Br(He,ne,"exchange",e)}static async _createWriteKeys(e=!1){return await Br(He,ne,"write",e)}async toJson(e){let t=this.publicExchangeKey,n=this.DID,i=await kr.subtle.exportKey("spki",t);return{publicExchangeKey:e?f(new Uint8Array(i),e):S(i),DID:n}}async sign(e,t=z){let n=this.writeKey,i=await j.sign(e,n.privateKey,t);return new Uint8Array(i)}async signAsString(e,t){let n=await this.sign(e,t);return S(n)}async encrypt(e,t,n,i,o){let a=t||this.exchangeKey.publicKey,y=n,c=i,u=y||await m.create({length:c||o}),g=await m.encrypt(typeof e=="string"?K(e):e,typeof u=="string"?await m.import(u):u),b=await Ke({key:u,publicKey:a}),w=W(b,g);return new Uint8Array(w)}async encryptAsString(e,t,n,i,o){let a=await this.encrypt(e,t,n,i,o);return f(a,"base64pad")}async decrypt(e,t,n){let i=ie(e,_),o=ri(this.exchangeKey.privateKey),a=i.slice(0,o),y=i.slice(o),c=await this.decryptKey(a);return await m.decrypt(y,c)}async decryptAsString(e,t,n){let i=await this.decrypt(e,t,n);return f(i)}async decryptKey(e){return await j.decrypt(e,this.exchangeKey.privateKey)}async decryptKeyAsString(e,t){let n=await j.decrypt(e,this.exchangeKey.privateKey);return f(n,t)}async getAesKey(e,t){if(!e)throw new Error("RSA requires an encrypted AES key to decrypt");if(typeof e=="string"){let n=await this.decryptKey(e);return await m.import(n)}else return e}};Object.assign(oe.prototype.sign,{asString:s(async function(r,e){return this.signAsString(r,e)},"asString")});Object.assign(oe.prototype.encrypt,{asString:s(async function(r,e,t,n){return this.encryptAsString(r,e,t,n)},"asString")});Object.assign(oe.prototype.decrypt,{asString:s(async function(r,e){return this.decryptAsString(r,e)},"asString")});async function ti(r,e,t){let n=je(t),i=await Te(n.publicKey.buffer,"SHA-256","signing");try{return j.verify(r,e,i)}catch{return!1}}s(ti,"verify");Object.assign(oe.prototype.decryptKey,{asString:s(async function(r,e){return this.decryptKeyAsString(r,e)},"asString")});async function Kt(r,e){let{content:t,publicKey:n}=r,i=e||await m.create(),o=await m.encrypt(typeof t=="string"?K(t):t,typeof i=="string"?await m.import(i):i),a=await Ke({key:i,publicKey:n});return W(a,o)}s(Kt,"encryptTo");Kt.asString=async function(r,e){let{content:t,publicKey:n}=r,i=e||await m.create(),o=await m.encrypt(typeof t=="string"?K(t):t,typeof i=="string"?await m.import(i):i,"arraybuffer"),a=await Ke({key:i,publicKey:n}),y=W(a,o);return f(new Uint8Array(y),"base64pad")};async function Ke({key:r,publicKey:e},t){let n;r instanceof CryptoKey?n=await m.export(r):n=r;let i=await j.encrypt(n,e);return t&&t==="arraybuffer"?i:new Uint8Array(i)}s(Ke,"encryptKeyTo");Ke.asString=async function({key:r,publicKey:e},t){let n=await Ke({key:r,publicKey:e});return t?f(n,t):S(n)};async function ni(r,e,t,n){let i=he(e)?e:await me(e),o=n?await kr.subtle.encrypt({name:H,iv:At(n)},i,At(r)):await ii(r,i);return t&&t==="arraybuffer"?o:new Uint8Array(o)}s(ni,"encrypt");async function ii(r,e,t){let n=J(r,t?.charsize??z),i=typeof e=="string"?await ve(e,t):e,o=t?.iv||Xe(T),a=await kr.subtle.encrypt({name:H,iv:o},i,n);return W(o,a)}s(ii,"encryptBytes");var Ut={};v(Ut,{EccKeys:()=>ee,default:()=>si,exportPublicKey:()=>ae,importPublicKey:()=>Ne,verify:()=>Et});var d=globalThis.crypto;function Q(r){return new Uint8Array(r).buffer}s(Q,"toArrayBuffer");var ee=class r extends Ae{static{s(this,"EccKeys")}static TYPE="ecc";static EXCHANGE_KEY_NAME=Cr;static WRITE_KEY_NAME=Pr;static INFO="keys";static async create(e,t,n){return await super.create(e,t,n)}get publicExchangeKey(){let e=this.exchangeKey.publicKey;return Object.assign(e,{asString:s(async t=>{let n=await ae(this.exchangeKey),i=new Uint8Array(n);return t?f(i,t):S(n)},"asString")})}get publicWriteKey(){let e=this.writeKey.publicKey;return Object.assign(e,{asString:s(async t=>{let n=await ae(this.writeKey),i=new Uint8Array(n);return t?f(i,t):S(n)},"asString")})}static async _createExchangeKeys(e=!1){return await d.subtle.generateKey({name:Ce},e,["deriveKey","deriveBits"])}static async _createWriteKeys(e=!1){return await d.subtle.generateKey({name:te},e,["sign","verify"])}static async load(e={session:!1}){return super.load(e)}async toJson(e){let t=this.DID,n=await ae(this.exchangeKey);return{publicExchangeKey:e?f(new Uint8Array(n),e):S(n),DID:t}}async wrap(e,t,n){let i=await r._createExchangeKeys(!1),o=await ae(i),a=new Uint8Array(o),y=new Uint8Array(await d.subtle.exportKey("raw",t)),c=n||"key-wrap",u=d.getRandomValues(new Uint8Array(C)),g=await Ie(i.privateKey,t,u,wt(a,y,c)),b,w=!1;if(e instanceof CryptoKey){let D=await d.subtle.exportKey("raw",e);b=new Uint8Array(D),w=!0}else typeof e=="string"?(b=K(e,"base64pad"),w=!0):b=e;let k=d.getRandomValues(new Uint8Array(T)),p=await d.subtle.encrypt({name:I,iv:k},g,Q(b));w&&b.fill(0);let h=new Uint8Array(k),B=new Uint8Array(p),U=1+C+h.length+B.length,x=new Uint8Array(U);x[0]=Ve,x.set(u,1),x.set(h,1+C),x.set(B,1+C+h.length);let E=xt(a,y,x,c),P=await this.sign(E);return{enc:S(a),wrappedKey:S(x),signature:f(P,"base64pad")}}async unwrap(e,t,n={}){let{enc:i,wrappedKey:o,signature:a}=e,y=n.info,c=n.extractable??!0;if(!t)throw new Error("`unwrap` requires the DID of the sender");if(!a)throw new Error("The wrapped key is not signed");let u=K(i,"base64pad");if(u.length!==O)throw new Error(`\`enc\` must be a ${O}-byte X25519 public key, got ${u.length} bytes`);let g=new Uint8Array(_(o)),b=y||"key-wrap",w=1+C+T+Er;if(g.length<w)throw new Error(`Wrapped key must be at least ${w} bytes, got ${g.length} bytes`);let k=g[0];if(k!==Ve)throw new Error(`Unsupported wrapped key format version: ${k}`);let p=new Uint8Array(await ae(this.exchangeKey)),h=xt(u,p,g,b);if(!await Et(h,a,t))throw new Error("Invalid signature for the wrapped key");let U=await Ne(i,"X25519","exchange"),x=g.slice(1,1+C),E=g.slice(1+C,1+C+T),P=g.slice(1+C+T),D=await Ie(this.exchangeKey.privateKey,U,x,wt(u,p,b)),M=await d.subtle.decrypt({name:I,iv:E},D,Q(P));return await d.subtle.importKey("raw",M,{name:I},c,["encrypt","decrypt"])}async encrypt(e,t,n,i,o){let a=d.getRandomValues(new Uint8Array(C)),y=t||this.exchangeKey.publicKey,c;typeof y=="string"?c=await Ne(y,"X25519","exchange"):c=y;let u=await r._createExchangeKeys(!1),g=i?i instanceof CryptoKey?i:await m.import(i):await Ie(u.privateKey,c,a,n||r.INFO,o),b=d.getRandomValues(new Uint8Array(T)),w=typeof e=="string"?new TextEncoder().encode(e):e,k=await d.subtle.encrypt({name:I,iv:b},g,Q(w)),p=new Uint8Array(await ae(u)),h=new Uint8Array(a),B=new Uint8Array(b),U=new Uint8Array(k),x=p.length+h.length+B.length+U.length,E=new Uint8Array(x);return E.set(p,0),E.set(h,p.length),E.set(B,p.length+h.length),E.set(U,p.length+h.length+B.length),E}async encryptAsString(e,t,n,i,o){let a=await this.encrypt(e,t,n||r.INFO,i,o);return f(new Uint8Array(a),"base64pad")}async decrypt(e,t,n,i){let o=ie(e,_),a=o.slice(0,O),y=await d.subtle.importKey("raw",a,{name:Ce},!0,[]),c=o.slice(O,O+C),u=o.slice(O+C,O+C+T),g=o.slice(O+C+T),{privateKey:b}=this.exchangeKey,w=i?i instanceof CryptoKey?i:await m.import(i):await Ie(b,y,c,n||r.INFO);return await d.subtle.decrypt({name:t||I,iv:u},w,g)}async decryptAsString(e,t,n,i){let o=await this.decrypt(e,t,n,i);return f(new Uint8Array(o))}async getAesKey(e,t,n){e||(e=this.publicExchangeKey);let i;typeof e=="string"?i=await Ne(e,"X25519","exchange"):i=e;let o=n?new Uint8Array(typeof n=="string"?_(n):n):d.getRandomValues(new Uint8Array(C)),a=await Ie(this.exchangeKey.privateKey,i,o,t||r.INFO);return Object.assign(a,{salt:S(o)})}async sign(e,t){let n=new TextEncoder,i;typeof e=="string"?i=n.encode(e):e instanceof ArrayBuffer?i=new Uint8Array(e):i=e;let o=await d.subtle.sign({name:te},this.writeKey.privateKey,Q(i));return new Uint8Array(o)}async signAsString(e,t){let n=await this.sign(e,t);return f(n,"base64pad")}};Object.assign(ee.prototype.sign,{asString:s(async function(r,e){let t=await this.sign(r,e);return f(t,"base64pad")},"asString")});async function ae(r,e="raw"){return await d.subtle.exportKey(e,r.publicKey)}s(ae,"exportPublicKey");async function Ne(r,e,t){mt(t);let n=t==="exchange"?Ce:te,i=t==="exchange"?[]:["verify"],o=_(r),a=e==="X25519"?{name:n}:{name:n,namedCurve:e};return d.subtle.importKey("raw",o,a,!0,i)}s(Ne,"importPublicKey");var si={EccKeys:ee,importPublicKey:Ne};Object.assign(ee.prototype.encrypt,{asString:s(async function(r,e,t,n,i){return this.encryptAsString(r,e,t,n,i)},"asString")});Object.assign(ee.prototype.decrypt,{asString:s(async function(r,e){return this.decryptAsString(r,e)},"asString")});Object.assign(ee.prototype.sign,{asString:s(async function(r,e){return this.signAsString(r,e)},"asString")});async function Et(r,e,t){try{let n=je(t);if(n.type!=="ed25519")throw new Error(`Expected Ed25519 key for ECC verification, got ${n.type}`);let i=n.publicKey.slice(-32),o=await d.subtle.importKey("raw",i,{name:te},!0,["verify"]),a=new TextEncoder,y;typeof r=="string"?y=a.encode(r):r instanceof ArrayBuffer?y=new Uint8Array(r):y=r;let c;return typeof e=="string"?c=new Uint8Array(_(e)):c=e,await d.subtle.verify({name:te},o,Q(c),Q(y))}catch{return!1}}s(Et,"verify");function wt(r,e,t){let n=new TextEncoder().encode(t),i=new Uint8Array(r.length+e.length+n.length);return i.set(r,0),i.set(e,r.length),i.set(n,r.length+e.length),i}s(wt,"wrapKekInfo");function xt(r,e,t,n){let i=new TextEncoder().encode(n),o=new Uint8Array(4);new DataView(o.buffer).setUint32(0,t.length);let a=new Uint8Array(r.length+e.length+o.length+t.length+i.length),y=0;return a.set(r,y),y+=r.length,a.set(e,y),y+=e.length,a.set(o,y),y+=o.length,a.set(t,y),y+=t.length,a.set(i,y),a}s(xt,"wrapSignData");async function Ie(r,e,t,n,i){let o=new TextEncoder,a=typeof n=="string"?o.encode(n):n,y=await d.subtle.deriveBits({name:"X25519",public:e},r,256),c=await d.subtle.importKey("raw",y,"HKDF",!1,["deriveKey"]);return d.subtle.deriveKey({name:"HKDF",hash:"SHA-256",salt:t instanceof Uint8Array?Q(t):t,info:Q(a)},c,{name:"AES-GCM",length:i||q},!1,["encrypt","decrypt"])}s(Ie,"deriveKey");})();
|
|
3
|
+
-----END PUBLIC KEY-----`,"")}s(ri,"stripKeyHeader");function be(r){return typeof CryptoKey<"u"?r instanceof CryptoKey:Nr(r,"algorithm")&&Nr(r,"extractable")&&Nr(r,"type")}s(be,"isCryptoKey");function Nr(r,e){return typeof r=="object"&&r!=null&&e in r}s(Nr,"hasProp");function ti(r,e){return M.subtle.importKey("spki",r instanceof Uint8Array?g(r):r,{name:q,hash:Fe},!1,e)}s(ti,"importRsaKey");async function ke(r,e="rsa"){let t;if(r instanceof CryptoKey){e=r.algorithm.name.includes("RSA")?"rsa":"ed25519";let o=e==="ed25519"?"raw":"spki",a=await M.subtle.exportKey(o,r);t=new Uint8Array(a)}else t=r;let n=Ze.keyTypes[e]?.magicBytes;if(!n)throw new Error(`Key type '${e}' not supported, available types: ${Object.keys(Ze.keyTypes).join(", ")}`);let i=sr([n,t]);return W+l(i,"base58btc")}s(ke,"publicKeyToDid");function xo(r){let e=r.substring(W.length),t=b(e,"base58btc"),n=Object.entries(Ze.keyTypes).find(([o,a])=>Ke(g(t),g(a.magicBytes)));if(!n)throw new Error("Invalid key type");let i=n[0];if(i!=="ed25519"&&i!=="rsa")throw new Error(`Unsupported key type: ${i}`);return i}s(xo,"keyTypeFromDid");async function ee(r){return r instanceof CryptoKey?await M.subtle.exportKey("spki",r):await M.subtle.exportKey("spki",r.publicKey)}s(ee,"getPublicKeyAsArrayBuffer");async function Lr(r){let e=await ee(r);return new Uint8Array(e)}s(Lr,"getPublicKeyAsUint8Array");function Qe(r){if(!r.startsWith(W))throw new Error("Please use a base58-encoded DID formatted `did:key:z...`");let e=r.substring(W.length),t=b(e,"base58btc"),n=Object.entries(Ze.keyTypes).find(([o,a])=>Ke(g(t),g(a.magicBytes)));if(!n)throw new Error("Unsupported key algorithm.");let i=t.slice(n[1].magicBytes.length);return n[0]==="ed25519"&&i.length===44?{publicKey:i.slice(-32),type:n[0]}:{publicKey:i,type:n[0]}}s(Qe,"didToPublicKey");var ce=globalThis.crypto,m={create(r={alg:I,length:Z}){let e=r.length||Z,t=r.alg||I,n=r.extractable??!0;return ce.subtle.generateKey({name:t,length:e},n,["encrypt","decrypt"])},export:Object.assign(async r=>{let e=await ce.subtle.exportKey("raw",r);return new Uint8Array(e)},{asString:s(async(r,e)=>{let t=await m.export(r);return e?l(t,e):x(t)},"asString")}),import(r,e){return we(typeof r=="string"?T(r):r,void 0,e)},async exportAsString(r){let e=await m.export(r);return x(e)},encrypt:ni,async decrypt(r,e,t){let n=be(e)?e:await we(e),i=t?await ce.subtle.decrypt({name:G,iv:g(t)},n,typeof r=="string"?g(b(r,"base64pad")):r instanceof Uint8Array?g(r):r):await bt(r,n);return new Uint8Array(i)}};function we(r,e,t=!0){return ce.subtle.importKey("raw",r instanceof Uint8Array?g(r):r,{name:G,length:e||256},t,["encrypt","decrypt"])}s(we,"importAesKey");async function ni(r,e,t,n){let i=be(e)?e:await we(e),o=n?await ce.subtle.encrypt({name:G,iv:g(n)},i,r instanceof ArrayBuffer?r:g(typeof r=="string"?b(r):r)):await ii(r,i);return t&&t==="arraybuffer"?o:new Uint8Array(o)}s(ni,"encrypt");async function ii(r,e,t){let n=Q(r,t?.charsize??H),i=typeof e=="string"?await Ne(e,t):e,o=t?.iv||Je(P),a=await ce.subtle.encrypt({name:G,iv:o},i,n);return j(o,a)}s(ii,"encryptBytes");async function bt(r,e,t){let n=$e(r),i=typeof e=="string"?await Ne(e,t):e,o=n.slice(0,P),a=n.slice(P);return await ce.subtle.decrypt({name:I,iv:o},i,a)}s(bt,"decryptBytes");function er(r){return new Promise((e,t)=>{r.oncomplete=r.onsuccess=()=>e(r.result),r.onabort=r.onerror=()=>t(r.error)})}s(er,"promisifyRequest");function si(r,e){let t,n=s(()=>{if(t)return t;let i=indexedDB.open(r);return i.onupgradeneeded=()=>i.result.createObjectStore(e),t=er(i),t.then(o=>{o.onclose=()=>t=void 0},()=>{t=void 0}),t},"getDB");return(i,o)=>n().then(a=>o(a.transaction(e,i).objectStore(e)))}s(si,"createStore");var kr;function Mr(){return kr||(kr=si("keyval-store","keyval")),kr}s(Mr,"defaultGetStore");function Me(r,e=Mr()){return e("readonly",t=>er(t.get(r)))}s(Me,"get");function Rr(r,e,t=Mr()){return t("readwrite",n=>(n.put(e,r),er(n.transaction)))}s(Rr,"set");function Or(r,e=Mr()){return e("readwrite",t=>(r.forEach(n=>t.delete(n)),er(t.transaction)))}s(Or,"delMany");var No=new Error("Key does not exist. Make sure you properly instantiated the keystore."),Lo=new Error("Retrieved a symmetric key when an asymmetric keypair was expected. Please use a different key name."),ko=new Error("Retrieved an asymmetric keypair when an symmetric key was expected. Please use a different key name."),Mo=new Error("ECC is not enabled for this browser. Please use RSA instead."),Ro=new Error("Cryptosystem not supported. Please use ECC or RSA"),oi=new Error("Invalid key use. Please use 'exchange' or 'write'"),Oo=new Error("Max must be less than 256 and greater than 0"),xe=class extends Error{static{s(this,"KeysDeletedError")}constructor(e){super(e||"These keys were deleted"),this.name="KeysDeletedError"}};function xt(r){ai(r,["exchange","write","signing"],oi)}s(xt,"checkValidKeyUse");function ai(r,e,t){if(!e.some(i=>i===r))throw t}s(ai,"checkValid");var Ee=class r{static{s(this,"AbstractKeys")}DID;hasPersisted;isSessionOnly;destroyed;exchangeKeyName;writeKeyName;static EXCHANGE_KEY_NAME;static WRITE_KEY_NAME;static _instance;_exchangeKey;_writeKey;constructor(e){let{keys:t}=e,n=this.constructor;this.DID=e.did,this._exchangeKey=t.exchange,this._writeKey=t.write,this.hasPersisted=e.hasPersisted,this.isSessionOnly=!!e.isSessionOnly,this.destroyed=!1,this.exchangeKeyName=e.exchangeKeyName||n.EXCHANGE_KEY_NAME,this.writeKeyName=e.writeKeyName||n.WRITE_KEY_NAME}get exchangeKey(){if(this.destroyed||!this._exchangeKey)throw new xe;return this._exchangeKey}get writeKey(){if(this.destroyed||!this._writeKey)throw new xe;return this._writeKey}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:s(async t=>{let n=await ee(this.writeKey),i=new Uint8Array(n);return t?l(i,t):x(i)},"asString")})}get publicExchangeKey(){let e=this.exchangeKey.publicKey;return Object.assign(e,{asString:s(async t=>{let n=await ee(this.exchangeKey),i=new Uint8Array(n);return t?l(i,t):x(i)},"asString")})}get privateWriteKey(){return this.writeKey.privateKey}get privateExchangeKey(){return this.exchangeKey.privateKey}get deviceName(){return r.deviceName(this.DID)}static deviceName(e){return yi(e)}async persist(){if(this.destroyed)throw new xe;this.isSessionOnly||(await Promise.all([Rr(this.exchangeKeyName,this.exchangeKey),Rr(this.writeKeyName,this.writeKey)]),this.hasPersisted=!0)}async delete(){let e=this.exchangeKeyName,t=this.writeKeyName;await Or([e,t]),this.constructor._invalidate(e,t),this._destroy()}_destroy(){this.destroyed=!0,this.hasPersisted=!1,this._exchangeKey=null,this._writeKey=null}static _invalidate(e,t){let n=this._instance;n&&n.exchangeKeyName===e&&n.writeKeyName===t&&(n._destroy(),this._instance=null)}static async delete(e={}){let t=e.encryptionKeyName||this.EXCHANGE_KEY_NAME,n=e.writeKeyName||this.WRITE_KEY_NAME;await Or([t,n]),this._invalidate(t,n)}async getDeviceName(){return r.deviceName(this.DID)}static _createExchangeKeys(e){throw new Error("The child should implement this")}static _createWriteKeys(e){throw new Error("The child should implement this")}static _keyNames(e){return e?{exchangeKeyName:`${e}.${this.EXCHANGE_KEY_NAME}`,writeKeyName:`${e}.${this.WRITE_KEY_NAME}`}:{exchangeKeyName:this.EXCHANGE_KEY_NAME,writeKeyName:this.WRITE_KEY_NAME}}static async create(e,t,n){let i=n?.exchangeKeys||await this._createExchangeKeys(t),o=n?.writeKeys||await this._createWriteKeys(t),a=await ee(o),y=await ke(new Uint8Array(a),this.TYPE==="ecc"?"ed25519":"rsa"),{exchangeKeyName:c,writeKeyName:p}=this._keyNames(n?.dbKey),f=new this({keys:{exchange:i,write:o},did:y,hasPersisted:!1,isSessionOnly:!!e,exchangeKeyName:c,writeKeyName:p});return this._instance=f,f}static async exist(e={}){let t=await Me(e.writeKeyName||this.WRITE_KEY_NAME),n=await Me(e.encryptionKeyName||this.EXCHANGE_KEY_NAME);return!(!t||!n)}static async load(e={session:!1}){let t=e.persist!==!1,n=this._keyNames(e.dbKey),i=e.encryptionKeyName||n.exchangeKeyName,o=e.writeKeyName||n.writeKeyName,a=this._instance;if(a&&!a.destroyed&&a.exchangeKeyName===i&&a.writeKeyName===o)return t&&!a.hasPersisted&&await a.persist(),a;let y=!0,c=await Me(i),p=await Me(o);c||(y=!1,c=await this._createExchangeKeys(e.extractable)),p||(y=!1,p=await this._createWriteKeys(e.extractable));let f=await ee(p),A=await ke(new Uint8Array(f),this.TYPE==="ecc"?"ed25519":"rsa"),w=new this({keys:{exchange:c,write:p},did:A,hasPersisted:y,isSessionOnly:!!e.session,exchangeKeyName:i,writeKeyName:o});return this._instance=w,t&&!y&&await w.persist(),w}};async function Et(r,e){let{content:t,publicKey:n}=r,i=e||await m.create(),o=await m.encrypt(typeof t=="string"?b(t):t,typeof i=="string"?await m.import(i):i),a=await zr({key:i,publicKey:n});return j(a,o)}s(Et,"encryptTo");Et.asString=async function(r,e){let t=await Et(r,e);return l(new Uint8Array(t),"base64pad")};async function zr({key:r,publicKey:e},t){let n;r instanceof CryptoKey?n=await m.export(r):n=r;let i=await X.encrypt(n,e);return t&&t==="arraybuffer"?i:new Uint8Array(i)}s(zr,"encryptKeyTo");zr.asString=async function({key:r,publicKey:e},t){let n=await zr({key:r,publicKey:e});return t?l(n,t):x(n)};async function yi(r){let e=await dt(new TextEncoder().encode(r.normalize("NFD")));return l(e,"base32").slice(0,32)}s(yi,"getDeviceName");var Hr=globalThis.crypto;function Ut(r){return new Uint8Array(r).buffer}s(Ut,"toArrayBuffer");function ci(r){return r.algorithm.modulusLength/8}s(ci,"rsaCiphertextByteLength");var pe=class extends Ee{static{s(this,"RsaKeys")}static TYPE="rsa";static INFO="keys";static EXCHANGE_KEY_NAME=Br;static WRITE_KEY_NAME=Tr;static async create(e,t,n){return await super.create(e,t,n)}static async load(e={session:!1}){return super.load(e)}static async _createExchangeKeys(e=!1){return await Ir(We,ae,"exchange",e)}static async _createWriteKeys(e=!1){return await Ir(We,ae,"write",e)}async toJson(e){let t=this.publicExchangeKey,n=this.DID,i=await Hr.subtle.exportKey("spki",t);return{publicExchangeKey:e?l(new Uint8Array(i),e):x(i),DID:n}}async sign(e,t=H){let n=this.writeKey,i=await X.sign(e,n.privateKey,t);return new Uint8Array(i)}async signAsString(e,t){let n=await this.sign(e,t);return x(n)}async encrypt(e,t,n,i,o){let a=t||this.exchangeKey.publicKey,y=n,c=i,p=y||await m.create({length:c||o}),f=await m.encrypt(typeof e=="string"?b(e):e,typeof p=="string"?await m.import(p):p),A=await Ue({key:p,publicKey:a}),w=j(A,f);return new Uint8Array(w)}async encryptAsString(e,t,n,i,o){let a=await this.encrypt(e,t,n,i,o);return l(a,"base64pad")}async decrypt(e,t,n){let i=ye(e,T),o=ci(this.exchangeKey.privateKey),a=i.slice(0,o),y=i.slice(o),c=await this.decryptKey(a);return await m.decrypt(y,c)}async decryptAsString(e,t,n){let i=await this.decrypt(e,t,n);return l(i)}async decryptKey(e){return await X.decrypt(e,this.exchangeKey.privateKey)}async decryptKeyAsString(e,t){let n=await X.decrypt(e,this.exchangeKey.privateKey);return l(n,t)}async getAesKey(e,t){if(!e)throw new Error("RSA requires an encrypted AES key to decrypt");if(typeof e=="string"){let n=await this.decryptKey(e);return await m.import(n)}else return e}};Object.assign(pe.prototype.sign,{asString:s(async function(r,e){return this.signAsString(r,e)},"asString")});Object.assign(pe.prototype.encrypt,{asString:s(async function(r,e,t,n){return this.encryptAsString(r,e,t,n)},"asString")});Object.assign(pe.prototype.decrypt,{asString:s(async function(r,e){return this.decryptAsString(r,e)},"asString")});async function pi(r,e,t){let n=qe(t),i=await Le(n.publicKey.buffer,"SHA-256","signing");try{return X.verify(r,e,i)}catch{return!1}}s(pi,"verify");Object.assign(pe.prototype.decryptKey,{asString:s(async function(r,e){return this.decryptKeyAsString(r,e)},"asString")});async function St(r,e){let{content:t,publicKey:n}=r,i=e||await m.create(),o=await m.encrypt(typeof t=="string"?b(t):t,typeof i=="string"?await m.import(i):i),a=await Ue({key:i,publicKey:n});return j(a,o)}s(St,"encryptTo");St.asString=async function(r,e){let{content:t,publicKey:n}=r,i=e||await m.create(),o=await m.encrypt(typeof t=="string"?b(t):t,typeof i=="string"?await m.import(i):i,"arraybuffer"),a=await Ue({key:i,publicKey:n}),y=j(a,o);return l(new Uint8Array(y),"base64pad")};async function Ue({key:r,publicKey:e},t){let n;r instanceof CryptoKey?n=await m.export(r):n=r;let i=await X.encrypt(n,e);return t&&t==="arraybuffer"?i:new Uint8Array(i)}s(Ue,"encryptKeyTo");Ue.asString=async function({key:r,publicKey:e},t){let n=await Ue({key:r,publicKey:e});return t?l(n,t):x(n)};async function ui(r,e,t,n){let i=be(e)?e:await we(e),o=n?await Hr.subtle.encrypt({name:G,iv:Ut(n)},i,Ut(r)):await fi(r,i);return t&&t==="arraybuffer"?o:new Uint8Array(o)}s(ui,"encrypt");async function fi(r,e,t){let n=Q(r,t?.charsize??H),i=typeof e=="string"?await Ne(e,t):e,o=t?.iv||Je(P),a=await Hr.subtle.encrypt({name:G,iv:o},i,n);return j(o,a)}s(fi,"encryptBytes");var Tt={};C(Tt,{EccKeys:()=>te,default:()=>li,exportPublicKey:()=>ue,importPublicKey:()=>Oe,verify:()=>Bt});var d=globalThis.crypto;function re(r){return new Uint8Array(r).buffer}s(re,"toArrayBuffer");var te=class r extends Ee{static{s(this,"EccKeys")}static TYPE="ecc";static EXCHANGE_KEY_NAME=Dr;static WRITE_KEY_NAME=_r;static INFO="keys";static async create(e,t,n){return await super.create(e,t,n)}get publicExchangeKey(){let e=this.exchangeKey.publicKey;return Object.assign(e,{asString:s(async t=>{let n=await ue(this.exchangeKey),i=new Uint8Array(n);return t?l(i,t):x(n)},"asString")})}get publicWriteKey(){let e=this.writeKey.publicKey;return Object.assign(e,{asString:s(async t=>{let n=await ue(this.writeKey),i=new Uint8Array(n);return t?l(i,t):x(n)},"asString")})}static async _createExchangeKeys(e=!1){return await d.subtle.generateKey({name:De},e,["deriveKey","deriveBits"])}static async _createWriteKeys(e=!1){return await d.subtle.generateKey({name:oe},e,["sign","verify"])}static async load(e={session:!1}){return super.load(e)}async toJson(e){let t=this.DID,n=await ue(this.exchangeKey);return{publicExchangeKey:e?l(new Uint8Array(n),e):x(n),DID:t}}async wrap(e,t,n){let i=await r._createExchangeKeys(!1),o=await ue(i),a=new Uint8Array(o),y=new Uint8Array(await d.subtle.exportKey("raw",t)),c=n||"key-wrap",p=d.getRandomValues(new Uint8Array(U)),f=await Re(i.privateKey,t,p,Pt(a,y,c)),A,w=!1;if(e instanceof CryptoKey){let v=await d.subtle.exportKey("raw",e);A=new Uint8Array(v),w=!0}else typeof e=="string"?(A=b(e,"base64pad"),w=!0):A=e;let R=d.getRandomValues(new Uint8Array(P)),N=await d.subtle.encrypt({name:I,iv:R},f,re(A));w&&A.fill(0);let D=new Uint8Array(R),F=new Uint8Array(N),u=1+U+D.length+F.length,h=new Uint8Array(u);h[0]=Ye,h.set(p,1),h.set(D,1+U),h.set(F,1+U+D.length);let E=vt(a,y,h,c),S=await this.sign(E);return{enc:x(a),wrappedKey:x(h),signature:l(S,"base64pad")}}async unwrap(e,t,n={}){let{enc:i,wrappedKey:o,signature:a}=e,y=n.info,c=n.extractable??!0;if(!t)throw new Error("`unwrap` requires the DID of the sender");if(!a)throw new Error("The wrapped key is not signed");let p=b(i,"base64pad");if(p.length!==z)throw new Error(`\`enc\` must be a ${z}-byte X25519 public key, got ${p.length} bytes`);let f=new Uint8Array(T(o)),A=y||"key-wrap",w=1+U+P+vr;if(f.length<w)throw new Error(`Wrapped key must be at least ${w} bytes, got ${f.length} bytes`);let R=f[0];if(R!==Ye)throw new Error(`Unsupported wrapped key format version: ${R}`);let N=new Uint8Array(await ue(this.exchangeKey)),D=vt(p,N,f,A);if(!await Bt(D,a,t))throw new Error("Invalid signature for the wrapped key");let u=await Oe(i,"X25519","exchange"),h=f.slice(1,1+U),E=f.slice(1+U,1+U+P),S=f.slice(1+U+P),v=await Re(this.exchangeKey.privateKey,u,h,Pt(p,N,A)),L=await d.subtle.decrypt({name:I,iv:E},v,re(S));return await d.subtle.importKey("raw",L,{name:I},c,["encrypt","decrypt"])}async encrypt(e,t,n,i,o){let a=d.getRandomValues(new Uint8Array(U)),y=t||this.exchangeKey.publicKey,c;typeof y=="string"?c=await Oe(y,"X25519","exchange"):c=y;let p=await r._createExchangeKeys(!1),f=i?i instanceof CryptoKey?i:await m.import(i):await Re(p.privateKey,c,a,n||r.INFO,o),A=d.getRandomValues(new Uint8Array(P)),w=typeof e=="string"?new TextEncoder().encode(e):e,R=await d.subtle.encrypt({name:I,iv:A},f,re(w)),N=new Uint8Array(await ue(p)),D=new Uint8Array(a),F=new Uint8Array(A),u=new Uint8Array(R),h=N.length+D.length+F.length+u.length,E=new Uint8Array(h);return E.set(N,0),E.set(D,N.length),E.set(F,N.length+D.length),E.set(u,N.length+D.length+F.length),E}async encryptAsString(e,t,n,i,o){let a=await this.encrypt(e,t,n||r.INFO,i,o);return l(new Uint8Array(a),"base64pad")}async decrypt(e,t,n,i){let o=ye(e,T),a=o.slice(0,z),y=await d.subtle.importKey("raw",a,{name:De},!0,[]),c=o.slice(z,z+U),p=o.slice(z+U,z+U+P),f=o.slice(z+U+P),{privateKey:A}=this.exchangeKey,w=i?i instanceof CryptoKey?i:await m.import(i):await Re(A,y,c,n||r.INFO);return await d.subtle.decrypt({name:t||I,iv:p},w,f)}async decryptAsString(e,t,n,i){let o=await this.decrypt(e,t,n,i);return l(new Uint8Array(o))}async getAesKey(e,t,n){e||(e=this.publicExchangeKey);let i;typeof e=="string"?i=await Oe(e,"X25519","exchange"):i=e;let o=n?new Uint8Array(typeof n=="string"?T(n):n):d.getRandomValues(new Uint8Array(U)),a=await Re(this.exchangeKey.privateKey,i,o,t||r.INFO);return Object.assign(a,{salt:x(o)})}async sign(e,t){let n=new TextEncoder,i;typeof e=="string"?i=n.encode(e):e instanceof ArrayBuffer?i=new Uint8Array(e):i=e;let o=await d.subtle.sign({name:oe},this.writeKey.privateKey,re(i));return new Uint8Array(o)}async signAsString(e,t){let n=await this.sign(e,t);return l(n,"base64pad")}};Object.assign(te.prototype.sign,{asString:s(async function(r,e){let t=await this.sign(r,e);return l(t,"base64pad")},"asString")});async function ue(r,e="raw"){return await d.subtle.exportKey(e,r.publicKey)}s(ue,"exportPublicKey");async function Oe(r,e,t){xt(t);let n=t==="exchange"?De:oe,i=t==="exchange"?[]:["verify"],o=T(r),a=e==="X25519"?{name:n}:{name:n,namedCurve:e};return d.subtle.importKey("raw",o,a,!0,i)}s(Oe,"importPublicKey");var li={EccKeys:te,importPublicKey:Oe};Object.assign(te.prototype.encrypt,{asString:s(async function(r,e,t,n,i){return this.encryptAsString(r,e,t,n,i)},"asString")});Object.assign(te.prototype.decrypt,{asString:s(async function(r,e){return this.decryptAsString(r,e)},"asString")});Object.assign(te.prototype.sign,{asString:s(async function(r,e){return this.signAsString(r,e)},"asString")});async function Bt(r,e,t){try{let n=qe(t);if(n.type!=="ed25519")throw new Error(`Expected Ed25519 key for ECC verification, got ${n.type}`);let i=n.publicKey.slice(-32),o=await d.subtle.importKey("raw",i,{name:oe},!0,["verify"]),a=new TextEncoder,y;typeof r=="string"?y=a.encode(r):r instanceof ArrayBuffer?y=new Uint8Array(r):y=r;let c;return typeof e=="string"?c=new Uint8Array(T(e)):c=e,await d.subtle.verify({name:oe},o,re(c),re(y))}catch{return!1}}s(Bt,"verify");function Pt(r,e,t){let n=new TextEncoder().encode(t),i=new Uint8Array(r.length+e.length+n.length);return i.set(r,0),i.set(e,r.length),i.set(n,r.length+e.length),i}s(Pt,"wrapKekInfo");function vt(r,e,t,n){let i=new TextEncoder().encode(n),o=new Uint8Array(4);new DataView(o.buffer).setUint32(0,t.length);let a=new Uint8Array(r.length+e.length+o.length+t.length+i.length),y=0;return a.set(r,y),y+=r.length,a.set(e,y),y+=e.length,a.set(o,y),y+=o.length,a.set(t,y),y+=t.length,a.set(i,y),a}s(vt,"wrapSignData");async function Re(r,e,t,n,i){let o=new TextEncoder,a=typeof n=="string"?o.encode(n):n,y=await d.subtle.deriveBits({name:"X25519",public:e},r,256),c=await d.subtle.importKey("raw",y,"HKDF",!1,["deriveKey"]);return d.subtle.deriveKey({name:"HKDF",hash:"SHA-256",salt:t instanceof Uint8Array?re(t):t,info:re(a)},c,{name:"AES-GCM",length:i||Z},!1,["encrypt","decrypt"])}s(Re,"deriveKey");})();
|