@unicitylabs/sphere-sdk 0.14.11 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -17
- package/dist/connect/index.cjs +17 -17
- package/dist/connect/index.cjs.map +1 -1
- package/dist/connect/index.js +17 -17
- package/dist/connect/index.js.map +1 -1
- package/dist/core/index.cjs +69 -84
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +5 -14
- package/dist/core/index.d.ts +5 -14
- package/dist/core/index.js +69 -84
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/connect/index.cjs +10 -3
- package/dist/impl/browser/connect/index.cjs.map +1 -1
- package/dist/impl/browser/connect/index.js +10 -3
- package/dist/impl/browser/connect/index.js.map +1 -1
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/nodejs/connect/index.cjs +9 -2
- package/dist/impl/nodejs/connect/index.cjs.map +1 -1
- package/dist/impl/nodejs/connect/index.js +9 -2
- package/dist/impl/nodejs/connect/index.js.map +1 -1
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/impl/wallet-api-v2/index.cjs +92 -92
- package/dist/impl/wallet-api-v2/index.cjs.map +1 -1
- package/dist/impl/wallet-api-v2/index.js +92 -92
- package/dist/impl/wallet-api-v2/index.js.map +1 -1
- package/dist/index.cjs +69 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -11
- package/dist/index.d.ts +6 -11
- package/dist/index.js +69 -84
- package/dist/index.js.map +1 -1
- package/dist/modules/payments-v2/index.cjs +116 -174
- package/dist/modules/payments-v2/index.cjs.map +1 -1
- package/dist/modules/payments-v2/index.d.cts +3 -5
- package/dist/modules/payments-v2/index.d.ts +3 -5
- package/dist/modules/payments-v2/index.js +114 -173
- package/dist/modules/payments-v2/index.js.map +1 -1
- package/dist/token-engine/index.cjs +43 -57
- package/dist/token-engine/index.cjs.map +1 -1
- package/dist/token-engine/index.d.cts +0 -4
- package/dist/token-engine/index.d.ts +0 -4
- package/dist/token-engine/index.js +43 -57
- package/dist/token-engine/index.js.map +1 -1
- package/package.json +3 -2
|
@@ -45,10 +45,6 @@ interface SphereValue {
|
|
|
45
45
|
* `token`, so it is NOT stored — only cached at runtime on SphereToken.value.
|
|
46
46
|
*/
|
|
47
47
|
interface TokenBlob {
|
|
48
|
-
/** Blob format version (sphere storage migrations; independent of SDK CBOR). */
|
|
49
|
-
readonly v: number;
|
|
50
|
-
/** NetworkId.id the token belongs to (mainnet=1 / testnet=2 / local=3). */
|
|
51
|
-
readonly network: number;
|
|
52
48
|
/**
|
|
53
49
|
* Genesis-stable token id — 64-char lowercase hex of the v2 `TokenId.bytes`
|
|
54
50
|
* (same across every state of the token). Stored on the blob so dedup / listing
|
|
@@ -45,10 +45,6 @@ interface SphereValue {
|
|
|
45
45
|
* `token`, so it is NOT stored — only cached at runtime on SphereToken.value.
|
|
46
46
|
*/
|
|
47
47
|
interface TokenBlob {
|
|
48
|
-
/** Blob format version (sphere storage migrations; independent of SDK CBOR). */
|
|
49
|
-
readonly v: number;
|
|
50
|
-
/** NetworkId.id the token belongs to (mainnet=1 / testnet=2 / local=3). */
|
|
51
|
-
readonly network: number;
|
|
52
48
|
/**
|
|
53
49
|
* Genesis-stable token id — 64-char lowercase hex of the v2 `TokenId.bytes`
|
|
54
50
|
* (same across every state of the token). Stored on the blob so dedup / listing
|
|
@@ -302,7 +302,15 @@ function resolveProofTimeoutMs(configured) {
|
|
|
302
302
|
return configured;
|
|
303
303
|
}
|
|
304
304
|
var TRANSIENT_HTTP_STATUSES = /* @__PURE__ */ new Set([408, 425, 429, 500, 502, 503, 504]);
|
|
305
|
+
var TransientSubmitAnswer = class extends Error {
|
|
306
|
+
constructor(status) {
|
|
307
|
+
super(`gateway is not ready to certify yet (${status})`);
|
|
308
|
+
this.status = status;
|
|
309
|
+
this.name = "TransientSubmitAnswer";
|
|
310
|
+
}
|
|
311
|
+
};
|
|
305
312
|
function isTransientGatewayError(err) {
|
|
313
|
+
if (err instanceof TransientSubmitAnswer) return true;
|
|
306
314
|
return err instanceof JsonRpcNetworkError && TRANSIENT_HTTP_STATUSES.has(err.status);
|
|
307
315
|
}
|
|
308
316
|
function pause(ms, signal) {
|
|
@@ -436,37 +444,9 @@ function randomUUID() {
|
|
|
436
444
|
return `${h[0]}${h[1]}${h[2]}${h[3]}-${h[4]}${h[5]}-${h[6]}${h[7]}-${h[8]}${h[9]}-${h[10]}${h[11]}${h[12]}${h[13]}${h[14]}${h[15]}`;
|
|
437
445
|
}
|
|
438
446
|
|
|
439
|
-
// token-engine/token-blob.ts
|
|
440
|
-
var TOKEN_BLOB_TAG = 39051n;
|
|
441
|
-
var TOKEN_BLOB_VERSION = 1;
|
|
442
|
-
function decodeTokenBlob(bytes) {
|
|
443
|
-
const tag = CborDeserializer.decodeTag(bytes);
|
|
444
|
-
if (tag.tag !== TOKEN_BLOB_TAG) {
|
|
445
|
-
throw new CborError(`Invalid TokenBlob tag: ${tag.tag}`);
|
|
446
|
-
}
|
|
447
|
-
const fields = CborDeserializer.decodeArray(tag.data, 4);
|
|
448
|
-
const v = Number(CborDeserializer.decodeUnsignedInteger(fields[0]));
|
|
449
|
-
if (v !== TOKEN_BLOB_VERSION) {
|
|
450
|
-
throw new CborError(`Unsupported TokenBlob version: ${v}`);
|
|
451
|
-
}
|
|
452
|
-
return {
|
|
453
|
-
v,
|
|
454
|
-
network: Number(CborDeserializer.decodeUnsignedInteger(fields[1])),
|
|
455
|
-
tokenId: CborDeserializer.decodeTextString(fields[2]),
|
|
456
|
-
token: CborDeserializer.decodeByteString(fields[3])
|
|
457
|
-
};
|
|
458
|
-
}
|
|
459
|
-
function unwrapTokenBlobBytes(bytes) {
|
|
460
|
-
try {
|
|
461
|
-
return decodeTokenBlob(bytes).token;
|
|
462
|
-
} catch {
|
|
463
|
-
return bytes;
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
|
|
467
447
|
// token-engine/blob-keys.ts
|
|
468
448
|
async function deriveDeliveryKeys(blobBytes) {
|
|
469
|
-
const token = await Token.fromCBOR(
|
|
449
|
+
const token = await Token.fromCBOR(blobBytes);
|
|
470
450
|
const stateHash = HexConverter.encode((await token.latestTransaction.calculateStateHash()).imprint);
|
|
471
451
|
return { tokenId: HexConverter.encode(token.id.bytes), stateHash };
|
|
472
452
|
}
|
|
@@ -940,8 +920,8 @@ function deriveRealization(privKeyHex, transferId, index, field) {
|
|
|
940
920
|
}
|
|
941
921
|
|
|
942
922
|
// token-engine/split-checkpoint.ts
|
|
943
|
-
var CHECKPOINT_VERSION =
|
|
944
|
-
var CHECKPOINT_SDK_VERSION = "@unicitylabs/state-transition-sdk@
|
|
923
|
+
var CHECKPOINT_VERSION = 2;
|
|
924
|
+
var CHECKPOINT_SDK_VERSION = "@unicitylabs/state-transition-sdk@3.0.1";
|
|
945
925
|
function bytesEqual(a, b) {
|
|
946
926
|
if (a.length !== b.length) return false;
|
|
947
927
|
for (let i = 0; i < a.length; i++) {
|
|
@@ -1091,13 +1071,11 @@ var SphereTokenEngine = class {
|
|
|
1091
1071
|
const data = params.value ? await SpherePaymentData.fromValue(params.value).encode() : null;
|
|
1092
1072
|
const transferId = this.resolveTransferId(options);
|
|
1093
1073
|
const opIndex = this.resolveOpIndex(options);
|
|
1094
|
-
const mintTx = await MintTransaction.create(
|
|
1095
|
-
this.deps.networkId,
|
|
1096
|
-
recipient,
|
|
1074
|
+
const mintTx = await MintTransaction.create(this.deps.networkId, recipient, {
|
|
1097
1075
|
data,
|
|
1098
|
-
new TokenType(deriveRealization(this.privateKeyHex, transferId, opIndex, "tokenType")),
|
|
1099
|
-
TokenSalt.fromBytes(deriveRealization(this.privateKeyHex, transferId, opIndex, "mint"))
|
|
1100
|
-
);
|
|
1076
|
+
tokenType: new TokenType(deriveRealization(this.privateKeyHex, transferId, opIndex, "tokenType")),
|
|
1077
|
+
salt: TokenSalt.fromBytes(deriveRealization(this.privateKeyHex, transferId, opIndex, "mint"))
|
|
1078
|
+
});
|
|
1101
1079
|
const certificationData = await CertificationData.fromMintTransaction(mintTx);
|
|
1102
1080
|
const proof = await this.submitAndAwaitProof(
|
|
1103
1081
|
certificationData,
|
|
@@ -1114,7 +1092,7 @@ var SphereTokenEngine = class {
|
|
|
1114
1092
|
const recipient = SignaturePredicate.create(params.recipientPubkey);
|
|
1115
1093
|
const tokenType = params.tokenType ? new TokenType(params.tokenType) : TokenType.generate();
|
|
1116
1094
|
const salt = params.salt ? TokenSalt.fromBytes(params.salt) : TokenSalt.generate();
|
|
1117
|
-
const mintTx = await MintTransaction.create(this.deps.networkId, recipient, params.data, tokenType, salt);
|
|
1095
|
+
const mintTx = await MintTransaction.create(this.deps.networkId, recipient, { data: params.data, tokenType, salt });
|
|
1118
1096
|
const certificationData = await CertificationData.fromMintTransaction(mintTx);
|
|
1119
1097
|
const proof = await this.submitAndAwaitProof(
|
|
1120
1098
|
certificationData,
|
|
@@ -1134,7 +1112,9 @@ var SphereTokenEngine = class {
|
|
|
1134
1112
|
const stateMask = StateMask.fromBytes(
|
|
1135
1113
|
deriveRealization(this.privateKeyHex, transferId, this.resolveOpIndex(options), "stateMask")
|
|
1136
1114
|
);
|
|
1137
|
-
const transferTx = await TransferTransaction.create(params.token.sdkToken, recipient, stateMask,
|
|
1115
|
+
const transferTx = await TransferTransaction.create(params.token.sdkToken, recipient, stateMask, {
|
|
1116
|
+
data: params.data ?? null
|
|
1117
|
+
});
|
|
1138
1118
|
const unlockScript = await SignaturePredicateUnlockScript.create(transferTx, this.deps.signingService);
|
|
1139
1119
|
const certificationData = await CertificationData.fromTransaction(transferTx, unlockScript);
|
|
1140
1120
|
const proof = await this.submitAndAwaitProof(
|
|
@@ -1161,12 +1141,11 @@ var SphereTokenEngine = class {
|
|
|
1161
1141
|
TokenSalt.fromBytes(deriveRealization(this.privateKeyHex, transferId, i, "salt"))
|
|
1162
1142
|
)
|
|
1163
1143
|
);
|
|
1164
|
-
const split = await TokenSplit.split(
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
);
|
|
1144
|
+
const split = await TokenSplit.split(params.token.sdkToken, decodeSpherePaymentData, requests, {
|
|
1145
|
+
burnStateMask: StateMask.fromBytes(
|
|
1146
|
+
deriveRealization(this.privateKeyHex, transferId, this.resolveOpIndex(options), "burn")
|
|
1147
|
+
)
|
|
1148
|
+
});
|
|
1170
1149
|
const burntToken = await this.resolveBurntToken({ params, split, transferId, options });
|
|
1171
1150
|
const settled = [];
|
|
1172
1151
|
for (let start = 0; start < split.tokens.length; start += MAX_MINT_CONCURRENCY) {
|
|
@@ -1246,9 +1225,14 @@ var SphereTokenEngine = class {
|
|
|
1246
1225
|
await Promise.all(
|
|
1247
1226
|
ctx.split.tokens.map(async (leg) => {
|
|
1248
1227
|
const data = await leg.paymentData.encode();
|
|
1249
|
-
const probe = await MintTransaction.create(leg.networkId, leg.recipient,
|
|
1228
|
+
const probe = await MintTransaction.create(leg.networkId, leg.recipient, {
|
|
1229
|
+
data,
|
|
1230
|
+
tokenType: leg.tokenType,
|
|
1231
|
+
salt: leg.salt,
|
|
1232
|
+
justification: null
|
|
1233
|
+
});
|
|
1250
1234
|
const response = await this.deps.client.getInclusionProof(await StateId.fromTransaction(probe));
|
|
1251
|
-
if (response.inclusionProof
|
|
1235
|
+
if (response.inclusionProof !== null) {
|
|
1252
1236
|
throw new SplitCheckpointLostError(
|
|
1253
1237
|
"a split mint leaf is certified on-chain but no burn checkpoint exists \u2014 outputs are unrecoverable"
|
|
1254
1238
|
);
|
|
@@ -1260,14 +1244,12 @@ var SphereTokenEngine = class {
|
|
|
1260
1244
|
async mintSplitOutput(splitToken, burntToken, options) {
|
|
1261
1245
|
const data = await splitToken.paymentData.encode();
|
|
1262
1246
|
const justification = SplitMintJustification.create(burntToken, splitToken.proofs).toCBOR();
|
|
1263
|
-
const mintTx = await MintTransaction.create(
|
|
1264
|
-
splitToken.networkId,
|
|
1265
|
-
splitToken.recipient,
|
|
1247
|
+
const mintTx = await MintTransaction.create(splitToken.networkId, splitToken.recipient, {
|
|
1266
1248
|
data,
|
|
1267
|
-
splitToken.tokenType,
|
|
1268
|
-
splitToken.salt,
|
|
1249
|
+
tokenType: splitToken.tokenType,
|
|
1250
|
+
salt: splitToken.salt,
|
|
1269
1251
|
justification
|
|
1270
|
-
);
|
|
1252
|
+
});
|
|
1271
1253
|
const certData = await CertificationData.fromMintTransaction(mintTx);
|
|
1272
1254
|
const proof = await this.submitSplitMintLeg(certData, mintTx, options);
|
|
1273
1255
|
const certified = await mintTx.toCertifiedTransaction(this.deps.trustBase, this.deps.predicateVerifier, this.deps.unicityCertificateVerifier, proof);
|
|
@@ -1312,7 +1294,7 @@ var SphereTokenEngine = class {
|
|
|
1312
1294
|
);
|
|
1313
1295
|
const stateId = await StateId.fromTransaction(probe);
|
|
1314
1296
|
const response = await this.deps.client.getInclusionProof(stateId);
|
|
1315
|
-
return response.inclusionProof
|
|
1297
|
+
return response.inclusionProof !== null;
|
|
1316
1298
|
}
|
|
1317
1299
|
// ── serialization ────────────────────────────────────────────────────────────
|
|
1318
1300
|
/** @inheritDoc — SDK-derived (Token.fromCBOR → latestTransaction.calculateStateHash().imprint). */
|
|
@@ -1396,7 +1378,13 @@ var SphereTokenEngine = class {
|
|
|
1396
1378
|
let submitRejectedCleanly = false;
|
|
1397
1379
|
try {
|
|
1398
1380
|
const { value: response, retried } = await retryTransient(
|
|
1399
|
-
() =>
|
|
1381
|
+
async () => {
|
|
1382
|
+
const answer = await this.deps.client.submitCertificationRequest(certificationData);
|
|
1383
|
+
if (String(answer.status) === String(CertificationStatus.SERVICE_NOT_READY)) {
|
|
1384
|
+
throw new TransientSubmitAnswer(String(answer.status));
|
|
1385
|
+
}
|
|
1386
|
+
return answer;
|
|
1387
|
+
},
|
|
1400
1388
|
signal,
|
|
1401
1389
|
this.deps.proofPollIntervalMs ?? DEFAULT_PROOF_POLL_INTERVAL_MS
|
|
1402
1390
|
);
|
|
@@ -1451,8 +1439,6 @@ var SphereTokenEngine = class {
|
|
|
1451
1439
|
}
|
|
1452
1440
|
}
|
|
1453
1441
|
const blob = {
|
|
1454
|
-
v: TOKEN_BLOB_VERSION,
|
|
1455
|
-
network: sdkToken.genesis.networkId.id,
|
|
1456
1442
|
tokenId: HexConverter.encode(sdkToken.id.bytes),
|
|
1457
1443
|
token: sdkToken.toCBOR()
|
|
1458
1444
|
};
|