@unicitylabs/sphere-sdk 0.17.6 → 0.18.0-dev.2
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/connect/chunks/{chunk-T4DZCXWS.js → chunk-FGQ6CKKK.js} +2 -2
- package/dist/connect/chunks/{chunk-T4DZCXWS.js.map → chunk-FGQ6CKKK.js.map} +1 -1
- package/dist/connect/chunks/{chunk-BRYRG2TL.js → chunk-JYBI36GK.js} +2 -2
- package/dist/connect/chunks/{chunk-MA32MTCD.js → chunk-OAAY2JEA.js} +2 -2
- package/dist/connect/index.cjs +1 -1
- package/dist/connect/index.cjs.map +1 -1
- package/dist/connect/index.js +3 -3
- package/dist/connect/internal/host.js +2 -2
- package/dist/core/index.cjs +304 -47
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +392 -320
- package/dist/core/index.d.ts +392 -320
- package/dist/core/index.js +304 -47
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/connect/index.cjs +1 -1
- package/dist/impl/browser/connect/index.cjs.map +1 -1
- package/dist/impl/browser/connect/index.js +2 -2
- package/dist/impl/wallet-api-v2/index.cjs +2 -0
- package/dist/impl/wallet-api-v2/index.cjs.map +1 -1
- package/dist/impl/wallet-api-v2/index.d.cts +30 -30
- package/dist/impl/wallet-api-v2/index.d.ts +30 -30
- package/dist/impl/wallet-api-v2/index.js +2 -0
- package/dist/impl/wallet-api-v2/index.js.map +1 -1
- package/dist/index.cjs +304 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +279 -154
- package/dist/index.d.ts +279 -154
- package/dist/index.js +304 -47
- package/dist/index.js.map +1 -1
- package/dist/modules/payments-v2/index.cjs +249 -28
- package/dist/modules/payments-v2/index.cjs.map +1 -1
- package/dist/modules/payments-v2/index.d.cts +252 -166
- package/dist/modules/payments-v2/index.d.ts +252 -166
- package/dist/modules/payments-v2/index.js +249 -28
- package/dist/modules/payments-v2/index.js.map +1 -1
- package/dist/token-engine/index.cjs +455 -427
- package/dist/token-engine/index.cjs.map +1 -1
- package/dist/token-engine/index.d.cts +26 -1
- package/dist/token-engine/index.d.ts +26 -1
- package/dist/token-engine/index.js +455 -427
- package/dist/token-engine/index.js.map +1 -1
- package/package.json +1 -1
- /package/dist/connect/chunks/{chunk-BRYRG2TL.js.map → chunk-JYBI36GK.js.map} +0 -0
- /package/dist/connect/chunks/{chunk-MA32MTCD.js.map → chunk-OAAY2JEA.js.map} +0 -0
|
@@ -291,6 +291,350 @@ function decodeSpherePaymentData(bytes) {
|
|
|
291
291
|
return Promise.resolve(SpherePaymentData.fromCBOR(bytes));
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
+
// node_modules/@noble/hashes/utils.js
|
|
295
|
+
function isBytes(a) {
|
|
296
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
297
|
+
}
|
|
298
|
+
function anumber(n, title = "") {
|
|
299
|
+
if (typeof n !== "number") {
|
|
300
|
+
const prefix = title && `"${title}" `;
|
|
301
|
+
throw new TypeError(`${prefix}expected number, got ${typeof n}`);
|
|
302
|
+
}
|
|
303
|
+
if (!Number.isSafeInteger(n) || n < 0) {
|
|
304
|
+
const prefix = title && `"${title}" `;
|
|
305
|
+
throw new RangeError(`${prefix}expected integer >= 0, got ${n}`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function abytes(value, length, title = "") {
|
|
309
|
+
const bytes = isBytes(value);
|
|
310
|
+
const len = value?.length;
|
|
311
|
+
const needsLen = length !== void 0;
|
|
312
|
+
if (!bytes || needsLen && len !== length) {
|
|
313
|
+
const prefix = title && `"${title}" `;
|
|
314
|
+
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
315
|
+
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
316
|
+
const message = prefix + "expected Uint8Array" + ofLen + ", got " + got;
|
|
317
|
+
if (!bytes)
|
|
318
|
+
throw new TypeError(message);
|
|
319
|
+
throw new RangeError(message);
|
|
320
|
+
}
|
|
321
|
+
return value;
|
|
322
|
+
}
|
|
323
|
+
function ahash(h) {
|
|
324
|
+
if (typeof h !== "function" || typeof h.create !== "function")
|
|
325
|
+
throw new TypeError("Hash must wrapped by utils.createHasher");
|
|
326
|
+
anumber(h.outputLen);
|
|
327
|
+
anumber(h.blockLen);
|
|
328
|
+
if (h.outputLen < 1)
|
|
329
|
+
throw new Error('"outputLen" must be >= 1');
|
|
330
|
+
if (h.blockLen < 1)
|
|
331
|
+
throw new Error('"blockLen" must be >= 1');
|
|
332
|
+
}
|
|
333
|
+
function aexists(instance, checkFinished = true) {
|
|
334
|
+
if (instance.destroyed)
|
|
335
|
+
throw new Error("Hash instance has been destroyed");
|
|
336
|
+
if (checkFinished && instance.finished)
|
|
337
|
+
throw new Error("Hash#digest() has already been called");
|
|
338
|
+
}
|
|
339
|
+
function aoutput(out, instance) {
|
|
340
|
+
abytes(out, void 0, "digestInto() output");
|
|
341
|
+
const min = instance.outputLen;
|
|
342
|
+
if (out.length < min) {
|
|
343
|
+
throw new RangeError('"digestInto() output" expected to be of length >=' + min);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function clean(...arrays) {
|
|
347
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
348
|
+
arrays[i].fill(0);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
function createView(arr) {
|
|
352
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
353
|
+
}
|
|
354
|
+
function rotr(word, shift) {
|
|
355
|
+
return word << 32 - shift | word >>> shift;
|
|
356
|
+
}
|
|
357
|
+
function createHasher(hashCons, info = {}) {
|
|
358
|
+
const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
|
|
359
|
+
const tmp = hashCons(void 0);
|
|
360
|
+
hashC.outputLen = tmp.outputLen;
|
|
361
|
+
hashC.blockLen = tmp.blockLen;
|
|
362
|
+
hashC.canXOF = tmp.canXOF;
|
|
363
|
+
hashC.create = (opts) => hashCons(opts);
|
|
364
|
+
Object.assign(hashC, info);
|
|
365
|
+
return Object.freeze(hashC);
|
|
366
|
+
}
|
|
367
|
+
var oidNist = (suffix) => ({
|
|
368
|
+
// Current NIST hashAlgs suffixes used here fit in one DER subidentifier octet.
|
|
369
|
+
// Larger suffix values would need base-128 OID encoding and a different length byte.
|
|
370
|
+
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
// node_modules/@noble/hashes/_md.js
|
|
374
|
+
function Chi(a, b, c) {
|
|
375
|
+
return a & b ^ ~a & c;
|
|
376
|
+
}
|
|
377
|
+
function Maj(a, b, c) {
|
|
378
|
+
return a & b ^ a & c ^ b & c;
|
|
379
|
+
}
|
|
380
|
+
var HashMD = class {
|
|
381
|
+
blockLen;
|
|
382
|
+
outputLen;
|
|
383
|
+
canXOF = false;
|
|
384
|
+
padOffset;
|
|
385
|
+
isLE;
|
|
386
|
+
// For partial updates less than block size
|
|
387
|
+
buffer;
|
|
388
|
+
view;
|
|
389
|
+
finished = false;
|
|
390
|
+
length = 0;
|
|
391
|
+
pos = 0;
|
|
392
|
+
destroyed = false;
|
|
393
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
394
|
+
this.blockLen = blockLen;
|
|
395
|
+
this.outputLen = outputLen;
|
|
396
|
+
this.padOffset = padOffset;
|
|
397
|
+
this.isLE = isLE;
|
|
398
|
+
this.buffer = new Uint8Array(blockLen);
|
|
399
|
+
this.view = createView(this.buffer);
|
|
400
|
+
}
|
|
401
|
+
update(data) {
|
|
402
|
+
aexists(this);
|
|
403
|
+
abytes(data);
|
|
404
|
+
const { view, buffer, blockLen } = this;
|
|
405
|
+
const len = data.length;
|
|
406
|
+
for (let pos = 0; pos < len; ) {
|
|
407
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
408
|
+
if (take === blockLen) {
|
|
409
|
+
const dataView = createView(data);
|
|
410
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
411
|
+
this.process(dataView, pos);
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
415
|
+
this.pos += take;
|
|
416
|
+
pos += take;
|
|
417
|
+
if (this.pos === blockLen) {
|
|
418
|
+
this.process(view, 0);
|
|
419
|
+
this.pos = 0;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
this.length += data.length;
|
|
423
|
+
this.roundClean();
|
|
424
|
+
return this;
|
|
425
|
+
}
|
|
426
|
+
digestInto(out) {
|
|
427
|
+
aexists(this);
|
|
428
|
+
aoutput(out, this);
|
|
429
|
+
this.finished = true;
|
|
430
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
431
|
+
let { pos } = this;
|
|
432
|
+
buffer[pos++] = 128;
|
|
433
|
+
clean(this.buffer.subarray(pos));
|
|
434
|
+
if (this.padOffset > blockLen - pos) {
|
|
435
|
+
this.process(view, 0);
|
|
436
|
+
pos = 0;
|
|
437
|
+
}
|
|
438
|
+
for (let i = pos; i < blockLen; i++)
|
|
439
|
+
buffer[i] = 0;
|
|
440
|
+
view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE);
|
|
441
|
+
this.process(view, 0);
|
|
442
|
+
const oview = createView(out);
|
|
443
|
+
const len = this.outputLen;
|
|
444
|
+
if (len % 4)
|
|
445
|
+
throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
446
|
+
const outLen = len / 4;
|
|
447
|
+
const state = this.get();
|
|
448
|
+
if (outLen > state.length)
|
|
449
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
450
|
+
for (let i = 0; i < outLen; i++)
|
|
451
|
+
oview.setUint32(4 * i, state[i], isLE);
|
|
452
|
+
}
|
|
453
|
+
digest() {
|
|
454
|
+
const { buffer, outputLen } = this;
|
|
455
|
+
this.digestInto(buffer);
|
|
456
|
+
const res = buffer.slice(0, outputLen);
|
|
457
|
+
this.destroy();
|
|
458
|
+
return res;
|
|
459
|
+
}
|
|
460
|
+
_cloneInto(to) {
|
|
461
|
+
to ||= new this.constructor();
|
|
462
|
+
to.set(...this.get());
|
|
463
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
464
|
+
to.destroyed = destroyed;
|
|
465
|
+
to.finished = finished;
|
|
466
|
+
to.length = length;
|
|
467
|
+
to.pos = pos;
|
|
468
|
+
if (length % blockLen)
|
|
469
|
+
to.buffer.set(buffer);
|
|
470
|
+
return to;
|
|
471
|
+
}
|
|
472
|
+
clone() {
|
|
473
|
+
return this._cloneInto();
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
477
|
+
1779033703,
|
|
478
|
+
3144134277,
|
|
479
|
+
1013904242,
|
|
480
|
+
2773480762,
|
|
481
|
+
1359893119,
|
|
482
|
+
2600822924,
|
|
483
|
+
528734635,
|
|
484
|
+
1541459225
|
|
485
|
+
]);
|
|
486
|
+
|
|
487
|
+
// node_modules/@noble/hashes/sha2.js
|
|
488
|
+
var SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
489
|
+
1116352408,
|
|
490
|
+
1899447441,
|
|
491
|
+
3049323471,
|
|
492
|
+
3921009573,
|
|
493
|
+
961987163,
|
|
494
|
+
1508970993,
|
|
495
|
+
2453635748,
|
|
496
|
+
2870763221,
|
|
497
|
+
3624381080,
|
|
498
|
+
310598401,
|
|
499
|
+
607225278,
|
|
500
|
+
1426881987,
|
|
501
|
+
1925078388,
|
|
502
|
+
2162078206,
|
|
503
|
+
2614888103,
|
|
504
|
+
3248222580,
|
|
505
|
+
3835390401,
|
|
506
|
+
4022224774,
|
|
507
|
+
264347078,
|
|
508
|
+
604807628,
|
|
509
|
+
770255983,
|
|
510
|
+
1249150122,
|
|
511
|
+
1555081692,
|
|
512
|
+
1996064986,
|
|
513
|
+
2554220882,
|
|
514
|
+
2821834349,
|
|
515
|
+
2952996808,
|
|
516
|
+
3210313671,
|
|
517
|
+
3336571891,
|
|
518
|
+
3584528711,
|
|
519
|
+
113926993,
|
|
520
|
+
338241895,
|
|
521
|
+
666307205,
|
|
522
|
+
773529912,
|
|
523
|
+
1294757372,
|
|
524
|
+
1396182291,
|
|
525
|
+
1695183700,
|
|
526
|
+
1986661051,
|
|
527
|
+
2177026350,
|
|
528
|
+
2456956037,
|
|
529
|
+
2730485921,
|
|
530
|
+
2820302411,
|
|
531
|
+
3259730800,
|
|
532
|
+
3345764771,
|
|
533
|
+
3516065817,
|
|
534
|
+
3600352804,
|
|
535
|
+
4094571909,
|
|
536
|
+
275423344,
|
|
537
|
+
430227734,
|
|
538
|
+
506948616,
|
|
539
|
+
659060556,
|
|
540
|
+
883997877,
|
|
541
|
+
958139571,
|
|
542
|
+
1322822218,
|
|
543
|
+
1537002063,
|
|
544
|
+
1747873779,
|
|
545
|
+
1955562222,
|
|
546
|
+
2024104815,
|
|
547
|
+
2227730452,
|
|
548
|
+
2361852424,
|
|
549
|
+
2428436474,
|
|
550
|
+
2756734187,
|
|
551
|
+
3204031479,
|
|
552
|
+
3329325298
|
|
553
|
+
]);
|
|
554
|
+
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
555
|
+
var SHA2_32B = class extends HashMD {
|
|
556
|
+
constructor(outputLen) {
|
|
557
|
+
super(64, outputLen, 8, false);
|
|
558
|
+
}
|
|
559
|
+
get() {
|
|
560
|
+
const { A, B, C, D, E, F, G, H } = this;
|
|
561
|
+
return [A, B, C, D, E, F, G, H];
|
|
562
|
+
}
|
|
563
|
+
// prettier-ignore
|
|
564
|
+
set(A, B, C, D, E, F, G, H) {
|
|
565
|
+
this.A = A | 0;
|
|
566
|
+
this.B = B | 0;
|
|
567
|
+
this.C = C | 0;
|
|
568
|
+
this.D = D | 0;
|
|
569
|
+
this.E = E | 0;
|
|
570
|
+
this.F = F | 0;
|
|
571
|
+
this.G = G | 0;
|
|
572
|
+
this.H = H | 0;
|
|
573
|
+
}
|
|
574
|
+
process(view, offset) {
|
|
575
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
|
576
|
+
SHA256_W[i] = view.getUint32(offset, false);
|
|
577
|
+
for (let i = 16; i < 64; i++) {
|
|
578
|
+
const W15 = SHA256_W[i - 15];
|
|
579
|
+
const W2 = SHA256_W[i - 2];
|
|
580
|
+
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
581
|
+
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
582
|
+
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
583
|
+
}
|
|
584
|
+
let { A, B, C, D, E, F, G, H } = this;
|
|
585
|
+
for (let i = 0; i < 64; i++) {
|
|
586
|
+
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
587
|
+
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
588
|
+
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
589
|
+
const T2 = sigma0 + Maj(A, B, C) | 0;
|
|
590
|
+
H = G;
|
|
591
|
+
G = F;
|
|
592
|
+
F = E;
|
|
593
|
+
E = D + T1 | 0;
|
|
594
|
+
D = C;
|
|
595
|
+
C = B;
|
|
596
|
+
B = A;
|
|
597
|
+
A = T1 + T2 | 0;
|
|
598
|
+
}
|
|
599
|
+
A = A + this.A | 0;
|
|
600
|
+
B = B + this.B | 0;
|
|
601
|
+
C = C + this.C | 0;
|
|
602
|
+
D = D + this.D | 0;
|
|
603
|
+
E = E + this.E | 0;
|
|
604
|
+
F = F + this.F | 0;
|
|
605
|
+
G = G + this.G | 0;
|
|
606
|
+
H = H + this.H | 0;
|
|
607
|
+
this.set(A, B, C, D, E, F, G, H);
|
|
608
|
+
}
|
|
609
|
+
roundClean() {
|
|
610
|
+
clean(SHA256_W);
|
|
611
|
+
}
|
|
612
|
+
destroy() {
|
|
613
|
+
this.destroyed = true;
|
|
614
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
615
|
+
clean(this.buffer);
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
var _SHA256 = class extends SHA2_32B {
|
|
619
|
+
// We cannot use array here since array allows indexing by variable
|
|
620
|
+
// which means optimizer/compiler cannot use registers.
|
|
621
|
+
A = SHA256_IV[0] | 0;
|
|
622
|
+
B = SHA256_IV[1] | 0;
|
|
623
|
+
C = SHA256_IV[2] | 0;
|
|
624
|
+
D = SHA256_IV[3] | 0;
|
|
625
|
+
E = SHA256_IV[4] | 0;
|
|
626
|
+
F = SHA256_IV[5] | 0;
|
|
627
|
+
G = SHA256_IV[6] | 0;
|
|
628
|
+
H = SHA256_IV[7] | 0;
|
|
629
|
+
constructor() {
|
|
630
|
+
super(32);
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
var sha2562 = /* @__PURE__ */ createHasher(
|
|
634
|
+
() => new _SHA256(),
|
|
635
|
+
/* @__PURE__ */ oidNist(1)
|
|
636
|
+
);
|
|
637
|
+
|
|
294
638
|
// token-engine/proof-wait.ts
|
|
295
639
|
var DEFAULT_PROOF_TIMEOUT_MS = 1e4;
|
|
296
640
|
function resolveProofTimeoutMs(configured) {
|
|
@@ -453,85 +797,6 @@ async function deriveDeliveryKeys(blobBytes) {
|
|
|
453
797
|
return { tokenId: HexConverter.encode(token.id.bytes), stateHash };
|
|
454
798
|
}
|
|
455
799
|
|
|
456
|
-
// node_modules/@noble/hashes/utils.js
|
|
457
|
-
function isBytes(a) {
|
|
458
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
459
|
-
}
|
|
460
|
-
function anumber(n, title = "") {
|
|
461
|
-
if (typeof n !== "number") {
|
|
462
|
-
const prefix = title && `"${title}" `;
|
|
463
|
-
throw new TypeError(`${prefix}expected number, got ${typeof n}`);
|
|
464
|
-
}
|
|
465
|
-
if (!Number.isSafeInteger(n) || n < 0) {
|
|
466
|
-
const prefix = title && `"${title}" `;
|
|
467
|
-
throw new RangeError(`${prefix}expected integer >= 0, got ${n}`);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
function abytes(value, length, title = "") {
|
|
471
|
-
const bytes = isBytes(value);
|
|
472
|
-
const len = value?.length;
|
|
473
|
-
const needsLen = length !== void 0;
|
|
474
|
-
if (!bytes || needsLen && len !== length) {
|
|
475
|
-
const prefix = title && `"${title}" `;
|
|
476
|
-
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
477
|
-
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
478
|
-
const message = prefix + "expected Uint8Array" + ofLen + ", got " + got;
|
|
479
|
-
if (!bytes)
|
|
480
|
-
throw new TypeError(message);
|
|
481
|
-
throw new RangeError(message);
|
|
482
|
-
}
|
|
483
|
-
return value;
|
|
484
|
-
}
|
|
485
|
-
function ahash(h) {
|
|
486
|
-
if (typeof h !== "function" || typeof h.create !== "function")
|
|
487
|
-
throw new TypeError("Hash must wrapped by utils.createHasher");
|
|
488
|
-
anumber(h.outputLen);
|
|
489
|
-
anumber(h.blockLen);
|
|
490
|
-
if (h.outputLen < 1)
|
|
491
|
-
throw new Error('"outputLen" must be >= 1');
|
|
492
|
-
if (h.blockLen < 1)
|
|
493
|
-
throw new Error('"blockLen" must be >= 1');
|
|
494
|
-
}
|
|
495
|
-
function aexists(instance, checkFinished = true) {
|
|
496
|
-
if (instance.destroyed)
|
|
497
|
-
throw new Error("Hash instance has been destroyed");
|
|
498
|
-
if (checkFinished && instance.finished)
|
|
499
|
-
throw new Error("Hash#digest() has already been called");
|
|
500
|
-
}
|
|
501
|
-
function aoutput(out, instance) {
|
|
502
|
-
abytes(out, void 0, "digestInto() output");
|
|
503
|
-
const min = instance.outputLen;
|
|
504
|
-
if (out.length < min) {
|
|
505
|
-
throw new RangeError('"digestInto() output" expected to be of length >=' + min);
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
function clean(...arrays) {
|
|
509
|
-
for (let i = 0; i < arrays.length; i++) {
|
|
510
|
-
arrays[i].fill(0);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
function createView(arr) {
|
|
514
|
-
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
515
|
-
}
|
|
516
|
-
function rotr(word, shift) {
|
|
517
|
-
return word << 32 - shift | word >>> shift;
|
|
518
|
-
}
|
|
519
|
-
function createHasher(hashCons, info = {}) {
|
|
520
|
-
const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
|
|
521
|
-
const tmp = hashCons(void 0);
|
|
522
|
-
hashC.outputLen = tmp.outputLen;
|
|
523
|
-
hashC.blockLen = tmp.blockLen;
|
|
524
|
-
hashC.canXOF = tmp.canXOF;
|
|
525
|
-
hashC.create = (opts) => hashCons(opts);
|
|
526
|
-
Object.assign(hashC, info);
|
|
527
|
-
return Object.freeze(hashC);
|
|
528
|
-
}
|
|
529
|
-
var oidNist = (suffix) => ({
|
|
530
|
-
// Current NIST hashAlgs suffixes used here fit in one DER subidentifier octet.
|
|
531
|
-
// Larger suffix values would need base-128 OID encoding and a different length byte.
|
|
532
|
-
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
|
|
533
|
-
});
|
|
534
|
-
|
|
535
800
|
// node_modules/@noble/hashes/hmac.js
|
|
536
801
|
var _HMAC = class {
|
|
537
802
|
oHash;
|
|
@@ -567,351 +832,86 @@ var _HMAC = class {
|
|
|
567
832
|
return this;
|
|
568
833
|
}
|
|
569
834
|
digestInto(out) {
|
|
570
|
-
aexists(this);
|
|
571
|
-
aoutput(out, this);
|
|
572
|
-
this.finished = true;
|
|
573
|
-
const buf = out.subarray(0, this.outputLen);
|
|
574
|
-
this.iHash.digestInto(buf);
|
|
575
|
-
this.oHash.update(buf);
|
|
576
|
-
this.oHash.digestInto(buf);
|
|
577
|
-
this.destroy();
|
|
578
|
-
}
|
|
579
|
-
digest() {
|
|
580
|
-
const out = new Uint8Array(this.oHash.outputLen);
|
|
581
|
-
this.digestInto(out);
|
|
582
|
-
return out;
|
|
583
|
-
}
|
|
584
|
-
_cloneInto(to) {
|
|
585
|
-
to ||= Object.create(Object.getPrototypeOf(this), {});
|
|
586
|
-
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
|
587
|
-
to = to;
|
|
588
|
-
to.finished = finished;
|
|
589
|
-
to.destroyed = destroyed;
|
|
590
|
-
to.blockLen = blockLen;
|
|
591
|
-
to.outputLen = outputLen;
|
|
592
|
-
to.oHash = oHash._cloneInto(to.oHash);
|
|
593
|
-
to.iHash = iHash._cloneInto(to.iHash);
|
|
594
|
-
return to;
|
|
595
|
-
}
|
|
596
|
-
clone() {
|
|
597
|
-
return this._cloneInto();
|
|
598
|
-
}
|
|
599
|
-
destroy() {
|
|
600
|
-
this.destroyed = true;
|
|
601
|
-
this.oHash.destroy();
|
|
602
|
-
this.iHash.destroy();
|
|
603
|
-
}
|
|
604
|
-
};
|
|
605
|
-
var hmac = /* @__PURE__ */ (() => {
|
|
606
|
-
const hmac_ = ((hash, key, message) => new _HMAC(hash, key).update(message).digest());
|
|
607
|
-
hmac_.create = (hash, key) => new _HMAC(hash, key);
|
|
608
|
-
return hmac_;
|
|
609
|
-
})();
|
|
610
|
-
|
|
611
|
-
// node_modules/@noble/hashes/hkdf.js
|
|
612
|
-
function extract(hash, ikm, salt) {
|
|
613
|
-
ahash(hash);
|
|
614
|
-
if (salt === void 0)
|
|
615
|
-
salt = new Uint8Array(hash.outputLen);
|
|
616
|
-
return hmac(hash, salt, ikm);
|
|
617
|
-
}
|
|
618
|
-
var HKDF_COUNTER = /* @__PURE__ */ Uint8Array.of(0);
|
|
619
|
-
var EMPTY_BUFFER = /* @__PURE__ */ Uint8Array.of();
|
|
620
|
-
function expand(hash, prk, info, length = 32) {
|
|
621
|
-
ahash(hash);
|
|
622
|
-
anumber(length, "length");
|
|
623
|
-
abytes(prk, void 0, "prk");
|
|
624
|
-
const olen = hash.outputLen;
|
|
625
|
-
if (prk.length < olen)
|
|
626
|
-
throw new Error('"prk" must be at least HashLen octets');
|
|
627
|
-
if (length > 255 * olen)
|
|
628
|
-
throw new Error("Length must be <= 255*HashLen");
|
|
629
|
-
const blocks = Math.ceil(length / olen);
|
|
630
|
-
if (info === void 0)
|
|
631
|
-
info = EMPTY_BUFFER;
|
|
632
|
-
else
|
|
633
|
-
abytes(info, void 0, "info");
|
|
634
|
-
const okm = new Uint8Array(blocks * olen);
|
|
635
|
-
const HMAC = hmac.create(hash, prk);
|
|
636
|
-
const HMACTmp = HMAC._cloneInto();
|
|
637
|
-
const T = new Uint8Array(HMAC.outputLen);
|
|
638
|
-
for (let counter = 0; counter < blocks; counter++) {
|
|
639
|
-
HKDF_COUNTER[0] = counter + 1;
|
|
640
|
-
HMACTmp.update(counter === 0 ? EMPTY_BUFFER : T).update(info).update(HKDF_COUNTER).digestInto(T);
|
|
641
|
-
okm.set(T, olen * counter);
|
|
642
|
-
HMAC._cloneInto(HMACTmp);
|
|
643
|
-
}
|
|
644
|
-
HMAC.destroy();
|
|
645
|
-
HMACTmp.destroy();
|
|
646
|
-
clean(T, HKDF_COUNTER);
|
|
647
|
-
return okm.slice(0, length);
|
|
648
|
-
}
|
|
649
|
-
var hkdf = (hash, ikm, salt, info, length) => expand(hash, extract(hash, ikm, salt), info, length);
|
|
650
|
-
|
|
651
|
-
// node_modules/@noble/hashes/_md.js
|
|
652
|
-
function Chi(a, b, c) {
|
|
653
|
-
return a & b ^ ~a & c;
|
|
654
|
-
}
|
|
655
|
-
function Maj(a, b, c) {
|
|
656
|
-
return a & b ^ a & c ^ b & c;
|
|
657
|
-
}
|
|
658
|
-
var HashMD = class {
|
|
659
|
-
blockLen;
|
|
660
|
-
outputLen;
|
|
661
|
-
canXOF = false;
|
|
662
|
-
padOffset;
|
|
663
|
-
isLE;
|
|
664
|
-
// For partial updates less than block size
|
|
665
|
-
buffer;
|
|
666
|
-
view;
|
|
667
|
-
finished = false;
|
|
668
|
-
length = 0;
|
|
669
|
-
pos = 0;
|
|
670
|
-
destroyed = false;
|
|
671
|
-
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
672
|
-
this.blockLen = blockLen;
|
|
673
|
-
this.outputLen = outputLen;
|
|
674
|
-
this.padOffset = padOffset;
|
|
675
|
-
this.isLE = isLE;
|
|
676
|
-
this.buffer = new Uint8Array(blockLen);
|
|
677
|
-
this.view = createView(this.buffer);
|
|
678
|
-
}
|
|
679
|
-
update(data) {
|
|
680
|
-
aexists(this);
|
|
681
|
-
abytes(data);
|
|
682
|
-
const { view, buffer, blockLen } = this;
|
|
683
|
-
const len = data.length;
|
|
684
|
-
for (let pos = 0; pos < len; ) {
|
|
685
|
-
const take = Math.min(blockLen - this.pos, len - pos);
|
|
686
|
-
if (take === blockLen) {
|
|
687
|
-
const dataView = createView(data);
|
|
688
|
-
for (; blockLen <= len - pos; pos += blockLen)
|
|
689
|
-
this.process(dataView, pos);
|
|
690
|
-
continue;
|
|
691
|
-
}
|
|
692
|
-
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
693
|
-
this.pos += take;
|
|
694
|
-
pos += take;
|
|
695
|
-
if (this.pos === blockLen) {
|
|
696
|
-
this.process(view, 0);
|
|
697
|
-
this.pos = 0;
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
this.length += data.length;
|
|
701
|
-
this.roundClean();
|
|
702
|
-
return this;
|
|
703
|
-
}
|
|
704
|
-
digestInto(out) {
|
|
705
|
-
aexists(this);
|
|
706
|
-
aoutput(out, this);
|
|
707
|
-
this.finished = true;
|
|
708
|
-
const { buffer, view, blockLen, isLE } = this;
|
|
709
|
-
let { pos } = this;
|
|
710
|
-
buffer[pos++] = 128;
|
|
711
|
-
clean(this.buffer.subarray(pos));
|
|
712
|
-
if (this.padOffset > blockLen - pos) {
|
|
713
|
-
this.process(view, 0);
|
|
714
|
-
pos = 0;
|
|
715
|
-
}
|
|
716
|
-
for (let i = pos; i < blockLen; i++)
|
|
717
|
-
buffer[i] = 0;
|
|
718
|
-
view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE);
|
|
719
|
-
this.process(view, 0);
|
|
720
|
-
const oview = createView(out);
|
|
721
|
-
const len = this.outputLen;
|
|
722
|
-
if (len % 4)
|
|
723
|
-
throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
724
|
-
const outLen = len / 4;
|
|
725
|
-
const state = this.get();
|
|
726
|
-
if (outLen > state.length)
|
|
727
|
-
throw new Error("_sha2: outputLen bigger than state");
|
|
728
|
-
for (let i = 0; i < outLen; i++)
|
|
729
|
-
oview.setUint32(4 * i, state[i], isLE);
|
|
835
|
+
aexists(this);
|
|
836
|
+
aoutput(out, this);
|
|
837
|
+
this.finished = true;
|
|
838
|
+
const buf = out.subarray(0, this.outputLen);
|
|
839
|
+
this.iHash.digestInto(buf);
|
|
840
|
+
this.oHash.update(buf);
|
|
841
|
+
this.oHash.digestInto(buf);
|
|
842
|
+
this.destroy();
|
|
730
843
|
}
|
|
731
844
|
digest() {
|
|
732
|
-
const
|
|
733
|
-
this.digestInto(
|
|
734
|
-
|
|
735
|
-
this.destroy();
|
|
736
|
-
return res;
|
|
845
|
+
const out = new Uint8Array(this.oHash.outputLen);
|
|
846
|
+
this.digestInto(out);
|
|
847
|
+
return out;
|
|
737
848
|
}
|
|
738
849
|
_cloneInto(to) {
|
|
739
|
-
to ||=
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
to.destroyed = destroyed;
|
|
850
|
+
to ||= Object.create(Object.getPrototypeOf(this), {});
|
|
851
|
+
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
|
852
|
+
to = to;
|
|
743
853
|
to.finished = finished;
|
|
744
|
-
to.
|
|
745
|
-
to.
|
|
746
|
-
|
|
747
|
-
|
|
854
|
+
to.destroyed = destroyed;
|
|
855
|
+
to.blockLen = blockLen;
|
|
856
|
+
to.outputLen = outputLen;
|
|
857
|
+
to.oHash = oHash._cloneInto(to.oHash);
|
|
858
|
+
to.iHash = iHash._cloneInto(to.iHash);
|
|
748
859
|
return to;
|
|
749
860
|
}
|
|
750
861
|
clone() {
|
|
751
862
|
return this._cloneInto();
|
|
752
863
|
}
|
|
753
|
-
};
|
|
754
|
-
var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
755
|
-
1779033703,
|
|
756
|
-
3144134277,
|
|
757
|
-
1013904242,
|
|
758
|
-
2773480762,
|
|
759
|
-
1359893119,
|
|
760
|
-
2600822924,
|
|
761
|
-
528734635,
|
|
762
|
-
1541459225
|
|
763
|
-
]);
|
|
764
|
-
|
|
765
|
-
// node_modules/@noble/hashes/sha2.js
|
|
766
|
-
var SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
767
|
-
1116352408,
|
|
768
|
-
1899447441,
|
|
769
|
-
3049323471,
|
|
770
|
-
3921009573,
|
|
771
|
-
961987163,
|
|
772
|
-
1508970993,
|
|
773
|
-
2453635748,
|
|
774
|
-
2870763221,
|
|
775
|
-
3624381080,
|
|
776
|
-
310598401,
|
|
777
|
-
607225278,
|
|
778
|
-
1426881987,
|
|
779
|
-
1925078388,
|
|
780
|
-
2162078206,
|
|
781
|
-
2614888103,
|
|
782
|
-
3248222580,
|
|
783
|
-
3835390401,
|
|
784
|
-
4022224774,
|
|
785
|
-
264347078,
|
|
786
|
-
604807628,
|
|
787
|
-
770255983,
|
|
788
|
-
1249150122,
|
|
789
|
-
1555081692,
|
|
790
|
-
1996064986,
|
|
791
|
-
2554220882,
|
|
792
|
-
2821834349,
|
|
793
|
-
2952996808,
|
|
794
|
-
3210313671,
|
|
795
|
-
3336571891,
|
|
796
|
-
3584528711,
|
|
797
|
-
113926993,
|
|
798
|
-
338241895,
|
|
799
|
-
666307205,
|
|
800
|
-
773529912,
|
|
801
|
-
1294757372,
|
|
802
|
-
1396182291,
|
|
803
|
-
1695183700,
|
|
804
|
-
1986661051,
|
|
805
|
-
2177026350,
|
|
806
|
-
2456956037,
|
|
807
|
-
2730485921,
|
|
808
|
-
2820302411,
|
|
809
|
-
3259730800,
|
|
810
|
-
3345764771,
|
|
811
|
-
3516065817,
|
|
812
|
-
3600352804,
|
|
813
|
-
4094571909,
|
|
814
|
-
275423344,
|
|
815
|
-
430227734,
|
|
816
|
-
506948616,
|
|
817
|
-
659060556,
|
|
818
|
-
883997877,
|
|
819
|
-
958139571,
|
|
820
|
-
1322822218,
|
|
821
|
-
1537002063,
|
|
822
|
-
1747873779,
|
|
823
|
-
1955562222,
|
|
824
|
-
2024104815,
|
|
825
|
-
2227730452,
|
|
826
|
-
2361852424,
|
|
827
|
-
2428436474,
|
|
828
|
-
2756734187,
|
|
829
|
-
3204031479,
|
|
830
|
-
3329325298
|
|
831
|
-
]);
|
|
832
|
-
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
833
|
-
var SHA2_32B = class extends HashMD {
|
|
834
|
-
constructor(outputLen) {
|
|
835
|
-
super(64, outputLen, 8, false);
|
|
836
|
-
}
|
|
837
|
-
get() {
|
|
838
|
-
const { A, B, C, D, E, F, G, H } = this;
|
|
839
|
-
return [A, B, C, D, E, F, G, H];
|
|
840
|
-
}
|
|
841
|
-
// prettier-ignore
|
|
842
|
-
set(A, B, C, D, E, F, G, H) {
|
|
843
|
-
this.A = A | 0;
|
|
844
|
-
this.B = B | 0;
|
|
845
|
-
this.C = C | 0;
|
|
846
|
-
this.D = D | 0;
|
|
847
|
-
this.E = E | 0;
|
|
848
|
-
this.F = F | 0;
|
|
849
|
-
this.G = G | 0;
|
|
850
|
-
this.H = H | 0;
|
|
851
|
-
}
|
|
852
|
-
process(view, offset) {
|
|
853
|
-
for (let i = 0; i < 16; i++, offset += 4)
|
|
854
|
-
SHA256_W[i] = view.getUint32(offset, false);
|
|
855
|
-
for (let i = 16; i < 64; i++) {
|
|
856
|
-
const W15 = SHA256_W[i - 15];
|
|
857
|
-
const W2 = SHA256_W[i - 2];
|
|
858
|
-
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
859
|
-
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
860
|
-
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
861
|
-
}
|
|
862
|
-
let { A, B, C, D, E, F, G, H } = this;
|
|
863
|
-
for (let i = 0; i < 64; i++) {
|
|
864
|
-
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
865
|
-
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
866
|
-
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
867
|
-
const T2 = sigma0 + Maj(A, B, C) | 0;
|
|
868
|
-
H = G;
|
|
869
|
-
G = F;
|
|
870
|
-
F = E;
|
|
871
|
-
E = D + T1 | 0;
|
|
872
|
-
D = C;
|
|
873
|
-
C = B;
|
|
874
|
-
B = A;
|
|
875
|
-
A = T1 + T2 | 0;
|
|
876
|
-
}
|
|
877
|
-
A = A + this.A | 0;
|
|
878
|
-
B = B + this.B | 0;
|
|
879
|
-
C = C + this.C | 0;
|
|
880
|
-
D = D + this.D | 0;
|
|
881
|
-
E = E + this.E | 0;
|
|
882
|
-
F = F + this.F | 0;
|
|
883
|
-
G = G + this.G | 0;
|
|
884
|
-
H = H + this.H | 0;
|
|
885
|
-
this.set(A, B, C, D, E, F, G, H);
|
|
886
|
-
}
|
|
887
|
-
roundClean() {
|
|
888
|
-
clean(SHA256_W);
|
|
889
|
-
}
|
|
890
864
|
destroy() {
|
|
891
865
|
this.destroyed = true;
|
|
892
|
-
this.
|
|
893
|
-
|
|
866
|
+
this.oHash.destroy();
|
|
867
|
+
this.iHash.destroy();
|
|
894
868
|
}
|
|
895
869
|
};
|
|
896
|
-
var
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
870
|
+
var hmac = /* @__PURE__ */ (() => {
|
|
871
|
+
const hmac_ = ((hash, key, message) => new _HMAC(hash, key).update(message).digest());
|
|
872
|
+
hmac_.create = (hash, key) => new _HMAC(hash, key);
|
|
873
|
+
return hmac_;
|
|
874
|
+
})();
|
|
875
|
+
|
|
876
|
+
// node_modules/@noble/hashes/hkdf.js
|
|
877
|
+
function extract(hash, ikm, salt) {
|
|
878
|
+
ahash(hash);
|
|
879
|
+
if (salt === void 0)
|
|
880
|
+
salt = new Uint8Array(hash.outputLen);
|
|
881
|
+
return hmac(hash, salt, ikm);
|
|
882
|
+
}
|
|
883
|
+
var HKDF_COUNTER = /* @__PURE__ */ Uint8Array.of(0);
|
|
884
|
+
var EMPTY_BUFFER = /* @__PURE__ */ Uint8Array.of();
|
|
885
|
+
function expand(hash, prk, info, length = 32) {
|
|
886
|
+
ahash(hash);
|
|
887
|
+
anumber(length, "length");
|
|
888
|
+
abytes(prk, void 0, "prk");
|
|
889
|
+
const olen = hash.outputLen;
|
|
890
|
+
if (prk.length < olen)
|
|
891
|
+
throw new Error('"prk" must be at least HashLen octets');
|
|
892
|
+
if (length > 255 * olen)
|
|
893
|
+
throw new Error("Length must be <= 255*HashLen");
|
|
894
|
+
const blocks = Math.ceil(length / olen);
|
|
895
|
+
if (info === void 0)
|
|
896
|
+
info = EMPTY_BUFFER;
|
|
897
|
+
else
|
|
898
|
+
abytes(info, void 0, "info");
|
|
899
|
+
const okm = new Uint8Array(blocks * olen);
|
|
900
|
+
const HMAC = hmac.create(hash, prk);
|
|
901
|
+
const HMACTmp = HMAC._cloneInto();
|
|
902
|
+
const T = new Uint8Array(HMAC.outputLen);
|
|
903
|
+
for (let counter = 0; counter < blocks; counter++) {
|
|
904
|
+
HKDF_COUNTER[0] = counter + 1;
|
|
905
|
+
HMACTmp.update(counter === 0 ? EMPTY_BUFFER : T).update(info).update(HKDF_COUNTER).digestInto(T);
|
|
906
|
+
okm.set(T, olen * counter);
|
|
907
|
+
HMAC._cloneInto(HMACTmp);
|
|
909
908
|
}
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
(
|
|
913
|
-
|
|
914
|
-
|
|
909
|
+
HMAC.destroy();
|
|
910
|
+
HMACTmp.destroy();
|
|
911
|
+
clean(T, HKDF_COUNTER);
|
|
912
|
+
return okm.slice(0, length);
|
|
913
|
+
}
|
|
914
|
+
var hkdf = (hash, ikm, salt, info, length) => expand(hash, extract(hash, ikm, salt), info, length);
|
|
915
915
|
|
|
916
916
|
// token-engine/realization.ts
|
|
917
917
|
var REALIZATION_HKDF_INFO_PREFIX = "sphere-realization-v1";
|
|
@@ -1425,6 +1425,19 @@ async function readTokenNft(token) {
|
|
|
1425
1425
|
}
|
|
1426
1426
|
}
|
|
1427
1427
|
|
|
1428
|
+
// token-engine/plugin-ops.ts
|
|
1429
|
+
function contextWithMintVerifiers(base, verifiers) {
|
|
1430
|
+
const registry = new MintJustificationVerifierService();
|
|
1431
|
+
for (const verifier of verifiers) registry.register(verifier);
|
|
1432
|
+
return new VerificationContext(
|
|
1433
|
+
base.trustBase,
|
|
1434
|
+
base.predicateVerifier,
|
|
1435
|
+
base.unicityCertificateVerifier,
|
|
1436
|
+
registry,
|
|
1437
|
+
new TokenIssuanceVerifierService(false)
|
|
1438
|
+
);
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1428
1441
|
// token-engine/split-checkpoint.ts
|
|
1429
1442
|
var CHECKPOINT_VERSION = 2;
|
|
1430
1443
|
var CHECKPOINT_SDK_VERSION = "@unicitylabs/state-transition-sdk@3.0.1";
|
|
@@ -1571,6 +1584,10 @@ var SphereTokenEngine = class {
|
|
|
1571
1584
|
const data = token.sdkToken.genesis.data;
|
|
1572
1585
|
return data ? new Uint8Array(data) : null;
|
|
1573
1586
|
}
|
|
1587
|
+
readTokenJustification(token) {
|
|
1588
|
+
const justification = token.sdkToken.genesis.justification;
|
|
1589
|
+
return justification ? new Uint8Array(justification) : null;
|
|
1590
|
+
}
|
|
1574
1591
|
readNft(token) {
|
|
1575
1592
|
return readTokenNft(token);
|
|
1576
1593
|
}
|
|
@@ -1602,7 +1619,7 @@ var SphereTokenEngine = class {
|
|
|
1602
1619
|
const recipient = SignaturePredicate.create(params.recipientPubkey);
|
|
1603
1620
|
const tokenType = params.tokenType ? new TokenType(params.tokenType) : TokenType.generate();
|
|
1604
1621
|
const salt = params.salt ? TokenSalt.fromBytes(params.salt) : TokenSalt.generate();
|
|
1605
|
-
const mintTx = await MintTransaction.create(this.deps.networkId, recipient, { data: params.data, tokenType, salt });
|
|
1622
|
+
const mintTx = await MintTransaction.create(this.deps.networkId, recipient, { data: params.data, tokenType, salt, justification: params.justification ?? null });
|
|
1606
1623
|
const certificationData = await CertificationData.fromMintTransaction(mintTx);
|
|
1607
1624
|
const proof = await this.submitAndAwaitProof(
|
|
1608
1625
|
certificationData,
|
|
@@ -1612,34 +1629,30 @@ var SphereTokenEngine = class {
|
|
|
1612
1629
|
options
|
|
1613
1630
|
);
|
|
1614
1631
|
const certified = await mintTx.toCertifiedTransaction(this.deps.trustBase, this.deps.predicateVerifier, this.deps.unicityCertificateVerifier, proof);
|
|
1615
|
-
const
|
|
1616
|
-
return wrapToken(
|
|
1632
|
+
const verifiers = params.mintJustificationVerifiers;
|
|
1633
|
+
return wrapToken(await Token.mint(certified, verifiers ? contextWithMintVerifiers(this.deps, verifiers) : this.deps.verificationContext));
|
|
1617
1634
|
}
|
|
1618
1635
|
buildNftMint(params) {
|
|
1619
1636
|
return planNftMint(this.deps, params);
|
|
1620
1637
|
}
|
|
1621
1638
|
async transfer(params, options) {
|
|
1622
1639
|
this.assertOwned(params.token);
|
|
1623
|
-
|
|
1624
|
-
|
|
1640
|
+
return this.spend(params.token, SignaturePredicate.create(params.recipientPubkey), params.data ?? null, options, "Transfer certification failed");
|
|
1641
|
+
}
|
|
1642
|
+
async burn(params, options) {
|
|
1643
|
+
this.assertOwned(params.token);
|
|
1644
|
+
return this.spend(params.token, BurnPredicate.create(sha2562(params.reasonBytes)), params.reasonBytes, options, "Burn certification failed");
|
|
1645
|
+
}
|
|
1646
|
+
async spend(token, recipient, data, options, failLabel) {
|
|
1625
1647
|
const stateMask = StateMask.fromBytes(
|
|
1626
|
-
deriveRealization(this.privateKeyHex,
|
|
1648
|
+
deriveRealization(this.privateKeyHex, this.resolveTransferId(options), this.resolveOpIndex(options), "stateMask")
|
|
1627
1649
|
);
|
|
1628
|
-
const transferTx = await TransferTransaction.create(
|
|
1629
|
-
data: params.data ?? null
|
|
1630
|
-
});
|
|
1650
|
+
const transferTx = await TransferTransaction.create(token.sdkToken, recipient, stateMask, { data });
|
|
1631
1651
|
const unlockScript = await SignaturePredicateUnlockScript.create(transferTx, this.deps.signingService);
|
|
1632
1652
|
const certificationData = await CertificationData.fromTransaction(transferTx, unlockScript);
|
|
1633
|
-
const proof = await this.submitAndAwaitProof(
|
|
1634
|
-
certificationData,
|
|
1635
|
-
transferTx,
|
|
1636
|
-
"Transfer certification failed",
|
|
1637
|
-
"TRANSFER_FAILED",
|
|
1638
|
-
options
|
|
1639
|
-
);
|
|
1653
|
+
const proof = await this.submitAndAwaitProof(certificationData, transferTx, failLabel, "TRANSFER_FAILED", options);
|
|
1640
1654
|
const certified = await transferTx.toCertifiedTransaction(this.deps.trustBase, this.deps.predicateVerifier, this.deps.unicityCertificateVerifier, proof);
|
|
1641
|
-
|
|
1642
|
-
return wrapToken(transferred);
|
|
1655
|
+
return wrapToken(await token.sdkToken.transfer(certified, this.deps.verificationContext));
|
|
1643
1656
|
}
|
|
1644
1657
|
async split(params, options) {
|
|
1645
1658
|
this.assertOwned(params.token);
|
|
@@ -1954,6 +1967,20 @@ var SphereTokenEngine = class {
|
|
|
1954
1967
|
|
|
1955
1968
|
// token-engine/factory.ts
|
|
1956
1969
|
var DEFAULT_VERIFICATION_POOL_SIZE = 4;
|
|
1970
|
+
function registerPluginVerifiers(registry, plugins) {
|
|
1971
|
+
for (const plugin of plugins ?? []) {
|
|
1972
|
+
for (const verifier of plugin.mintJustificationVerifiers ?? []) {
|
|
1973
|
+
try {
|
|
1974
|
+
registry.register(verifier);
|
|
1975
|
+
} catch (err) {
|
|
1976
|
+
throw new SphereError(
|
|
1977
|
+
`Token plugin '${plugin.id}' registers mint-reason tag ${verifier.tag} twice or over another plugin's: ` + (err instanceof Error ? err.message : String(err)),
|
|
1978
|
+
"INVALID_CONFIG"
|
|
1979
|
+
);
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1957
1984
|
function disposedError() {
|
|
1958
1985
|
return new SphereError(
|
|
1959
1986
|
"Verification worker pool disposed \u2014 the in-flight verification was cancelled",
|
|
@@ -2035,6 +2062,7 @@ async function createSphereTokenEngine(config) {
|
|
|
2035
2062
|
mintJustificationVerifier.register(
|
|
2036
2063
|
new SplitMintJustificationVerifier(decodeSpherePaymentData)
|
|
2037
2064
|
);
|
|
2065
|
+
registerPluginVerifiers(mintJustificationVerifier, config.plugins);
|
|
2038
2066
|
const deps = {
|
|
2039
2067
|
client: new StateTransitionClient(new AggregatorClient(config.aggregatorUrl, config.apiKey ?? null)),
|
|
2040
2068
|
trustBase,
|