@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
|
@@ -337,7 +337,15 @@ function resolveProofTimeoutMs(configured) {
|
|
|
337
337
|
return configured;
|
|
338
338
|
}
|
|
339
339
|
var TRANSIENT_HTTP_STATUSES = /* @__PURE__ */ new Set([408, 425, 429, 500, 502, 503, 504]);
|
|
340
|
+
var TransientSubmitAnswer = class extends Error {
|
|
341
|
+
constructor(status) {
|
|
342
|
+
super(`gateway is not ready to certify yet (${status})`);
|
|
343
|
+
this.status = status;
|
|
344
|
+
this.name = "TransientSubmitAnswer";
|
|
345
|
+
}
|
|
346
|
+
};
|
|
340
347
|
function isTransientGatewayError(err) {
|
|
348
|
+
if (err instanceof TransientSubmitAnswer) return true;
|
|
341
349
|
return err instanceof import_JsonRpcNetworkError.JsonRpcNetworkError && TRANSIENT_HTTP_STATUSES.has(err.status);
|
|
342
350
|
}
|
|
343
351
|
function pause(ms, signal) {
|
|
@@ -471,37 +479,9 @@ function randomUUID() {
|
|
|
471
479
|
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]}`;
|
|
472
480
|
}
|
|
473
481
|
|
|
474
|
-
// token-engine/token-blob.ts
|
|
475
|
-
var TOKEN_BLOB_TAG = 39051n;
|
|
476
|
-
var TOKEN_BLOB_VERSION = 1;
|
|
477
|
-
function decodeTokenBlob(bytes) {
|
|
478
|
-
const tag = import_CborDeserializer.CborDeserializer.decodeTag(bytes);
|
|
479
|
-
if (tag.tag !== TOKEN_BLOB_TAG) {
|
|
480
|
-
throw new import_CborError.CborError(`Invalid TokenBlob tag: ${tag.tag}`);
|
|
481
|
-
}
|
|
482
|
-
const fields = import_CborDeserializer.CborDeserializer.decodeArray(tag.data, 4);
|
|
483
|
-
const v = Number(import_CborDeserializer.CborDeserializer.decodeUnsignedInteger(fields[0]));
|
|
484
|
-
if (v !== TOKEN_BLOB_VERSION) {
|
|
485
|
-
throw new import_CborError.CborError(`Unsupported TokenBlob version: ${v}`);
|
|
486
|
-
}
|
|
487
|
-
return {
|
|
488
|
-
v,
|
|
489
|
-
network: Number(import_CborDeserializer.CborDeserializer.decodeUnsignedInteger(fields[1])),
|
|
490
|
-
tokenId: import_CborDeserializer.CborDeserializer.decodeTextString(fields[2]),
|
|
491
|
-
token: import_CborDeserializer.CborDeserializer.decodeByteString(fields[3])
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
function unwrapTokenBlobBytes(bytes) {
|
|
495
|
-
try {
|
|
496
|
-
return decodeTokenBlob(bytes).token;
|
|
497
|
-
} catch {
|
|
498
|
-
return bytes;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
|
|
502
482
|
// token-engine/blob-keys.ts
|
|
503
483
|
async function deriveDeliveryKeys(blobBytes) {
|
|
504
|
-
const token = await import_Token.Token.fromCBOR(
|
|
484
|
+
const token = await import_Token.Token.fromCBOR(blobBytes);
|
|
505
485
|
const stateHash = import_HexConverter.HexConverter.encode((await token.latestTransaction.calculateStateHash()).imprint);
|
|
506
486
|
return { tokenId: import_HexConverter.HexConverter.encode(token.id.bytes), stateHash };
|
|
507
487
|
}
|
|
@@ -975,8 +955,8 @@ function deriveRealization(privKeyHex, transferId, index, field) {
|
|
|
975
955
|
}
|
|
976
956
|
|
|
977
957
|
// token-engine/split-checkpoint.ts
|
|
978
|
-
var CHECKPOINT_VERSION =
|
|
979
|
-
var CHECKPOINT_SDK_VERSION = "@unicitylabs/state-transition-sdk@
|
|
958
|
+
var CHECKPOINT_VERSION = 2;
|
|
959
|
+
var CHECKPOINT_SDK_VERSION = "@unicitylabs/state-transition-sdk@3.0.1";
|
|
980
960
|
function bytesEqual(a, b) {
|
|
981
961
|
if (a.length !== b.length) return false;
|
|
982
962
|
for (let i = 0; i < a.length; i++) {
|
|
@@ -1126,13 +1106,11 @@ var SphereTokenEngine = class {
|
|
|
1126
1106
|
const data = params.value ? await SpherePaymentData.fromValue(params.value).encode() : null;
|
|
1127
1107
|
const transferId = this.resolveTransferId(options);
|
|
1128
1108
|
const opIndex = this.resolveOpIndex(options);
|
|
1129
|
-
const mintTx = await import_MintTransaction.MintTransaction.create(
|
|
1130
|
-
this.deps.networkId,
|
|
1131
|
-
recipient,
|
|
1109
|
+
const mintTx = await import_MintTransaction.MintTransaction.create(this.deps.networkId, recipient, {
|
|
1132
1110
|
data,
|
|
1133
|
-
new import_TokenType.TokenType(deriveRealization(this.privateKeyHex, transferId, opIndex, "tokenType")),
|
|
1134
|
-
import_TokenSalt.TokenSalt.fromBytes(deriveRealization(this.privateKeyHex, transferId, opIndex, "mint"))
|
|
1135
|
-
);
|
|
1111
|
+
tokenType: new import_TokenType.TokenType(deriveRealization(this.privateKeyHex, transferId, opIndex, "tokenType")),
|
|
1112
|
+
salt: import_TokenSalt.TokenSalt.fromBytes(deriveRealization(this.privateKeyHex, transferId, opIndex, "mint"))
|
|
1113
|
+
});
|
|
1136
1114
|
const certificationData = await import_CertificationData.CertificationData.fromMintTransaction(mintTx);
|
|
1137
1115
|
const proof = await this.submitAndAwaitProof(
|
|
1138
1116
|
certificationData,
|
|
@@ -1149,7 +1127,7 @@ var SphereTokenEngine = class {
|
|
|
1149
1127
|
const recipient = import_SignaturePredicate.SignaturePredicate.create(params.recipientPubkey);
|
|
1150
1128
|
const tokenType = params.tokenType ? new import_TokenType.TokenType(params.tokenType) : import_TokenType.TokenType.generate();
|
|
1151
1129
|
const salt = params.salt ? import_TokenSalt.TokenSalt.fromBytes(params.salt) : import_TokenSalt.TokenSalt.generate();
|
|
1152
|
-
const mintTx = await import_MintTransaction.MintTransaction.create(this.deps.networkId, recipient, params.data, tokenType, salt);
|
|
1130
|
+
const mintTx = await import_MintTransaction.MintTransaction.create(this.deps.networkId, recipient, { data: params.data, tokenType, salt });
|
|
1153
1131
|
const certificationData = await import_CertificationData.CertificationData.fromMintTransaction(mintTx);
|
|
1154
1132
|
const proof = await this.submitAndAwaitProof(
|
|
1155
1133
|
certificationData,
|
|
@@ -1169,7 +1147,9 @@ var SphereTokenEngine = class {
|
|
|
1169
1147
|
const stateMask = import_StateMask.StateMask.fromBytes(
|
|
1170
1148
|
deriveRealization(this.privateKeyHex, transferId, this.resolveOpIndex(options), "stateMask")
|
|
1171
1149
|
);
|
|
1172
|
-
const transferTx = await import_TransferTransaction.TransferTransaction.create(params.token.sdkToken, recipient, stateMask,
|
|
1150
|
+
const transferTx = await import_TransferTransaction.TransferTransaction.create(params.token.sdkToken, recipient, stateMask, {
|
|
1151
|
+
data: params.data ?? null
|
|
1152
|
+
});
|
|
1173
1153
|
const unlockScript = await import_SignaturePredicateUnlockScript.SignaturePredicateUnlockScript.create(transferTx, this.deps.signingService);
|
|
1174
1154
|
const certificationData = await import_CertificationData.CertificationData.fromTransaction(transferTx, unlockScript);
|
|
1175
1155
|
const proof = await this.submitAndAwaitProof(
|
|
@@ -1196,12 +1176,11 @@ var SphereTokenEngine = class {
|
|
|
1196
1176
|
import_TokenSalt.TokenSalt.fromBytes(deriveRealization(this.privateKeyHex, transferId, i, "salt"))
|
|
1197
1177
|
)
|
|
1198
1178
|
);
|
|
1199
|
-
const split = await import_TokenSplit.TokenSplit.split(
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
);
|
|
1179
|
+
const split = await import_TokenSplit.TokenSplit.split(params.token.sdkToken, decodeSpherePaymentData, requests, {
|
|
1180
|
+
burnStateMask: import_StateMask.StateMask.fromBytes(
|
|
1181
|
+
deriveRealization(this.privateKeyHex, transferId, this.resolveOpIndex(options), "burn")
|
|
1182
|
+
)
|
|
1183
|
+
});
|
|
1205
1184
|
const burntToken = await this.resolveBurntToken({ params, split, transferId, options });
|
|
1206
1185
|
const settled = [];
|
|
1207
1186
|
for (let start = 0; start < split.tokens.length; start += MAX_MINT_CONCURRENCY) {
|
|
@@ -1281,9 +1260,14 @@ var SphereTokenEngine = class {
|
|
|
1281
1260
|
await Promise.all(
|
|
1282
1261
|
ctx.split.tokens.map(async (leg) => {
|
|
1283
1262
|
const data = await leg.paymentData.encode();
|
|
1284
|
-
const probe = await import_MintTransaction.MintTransaction.create(leg.networkId, leg.recipient,
|
|
1263
|
+
const probe = await import_MintTransaction.MintTransaction.create(leg.networkId, leg.recipient, {
|
|
1264
|
+
data,
|
|
1265
|
+
tokenType: leg.tokenType,
|
|
1266
|
+
salt: leg.salt,
|
|
1267
|
+
justification: null
|
|
1268
|
+
});
|
|
1285
1269
|
const response = await this.deps.client.getInclusionProof(await import_StateId.StateId.fromTransaction(probe));
|
|
1286
|
-
if (response.inclusionProof
|
|
1270
|
+
if (response.inclusionProof !== null) {
|
|
1287
1271
|
throw new SplitCheckpointLostError(
|
|
1288
1272
|
"a split mint leaf is certified on-chain but no burn checkpoint exists \u2014 outputs are unrecoverable"
|
|
1289
1273
|
);
|
|
@@ -1295,14 +1279,12 @@ var SphereTokenEngine = class {
|
|
|
1295
1279
|
async mintSplitOutput(splitToken, burntToken, options) {
|
|
1296
1280
|
const data = await splitToken.paymentData.encode();
|
|
1297
1281
|
const justification = import_SplitMintJustification.SplitMintJustification.create(burntToken, splitToken.proofs).toCBOR();
|
|
1298
|
-
const mintTx = await import_MintTransaction.MintTransaction.create(
|
|
1299
|
-
splitToken.networkId,
|
|
1300
|
-
splitToken.recipient,
|
|
1282
|
+
const mintTx = await import_MintTransaction.MintTransaction.create(splitToken.networkId, splitToken.recipient, {
|
|
1301
1283
|
data,
|
|
1302
|
-
splitToken.tokenType,
|
|
1303
|
-
splitToken.salt,
|
|
1284
|
+
tokenType: splitToken.tokenType,
|
|
1285
|
+
salt: splitToken.salt,
|
|
1304
1286
|
justification
|
|
1305
|
-
);
|
|
1287
|
+
});
|
|
1306
1288
|
const certData = await import_CertificationData.CertificationData.fromMintTransaction(mintTx);
|
|
1307
1289
|
const proof = await this.submitSplitMintLeg(certData, mintTx, options);
|
|
1308
1290
|
const certified = await mintTx.toCertifiedTransaction(this.deps.trustBase, this.deps.predicateVerifier, this.deps.unicityCertificateVerifier, proof);
|
|
@@ -1347,7 +1329,7 @@ var SphereTokenEngine = class {
|
|
|
1347
1329
|
);
|
|
1348
1330
|
const stateId = await import_StateId.StateId.fromTransaction(probe);
|
|
1349
1331
|
const response = await this.deps.client.getInclusionProof(stateId);
|
|
1350
|
-
return response.inclusionProof
|
|
1332
|
+
return response.inclusionProof !== null;
|
|
1351
1333
|
}
|
|
1352
1334
|
// ── serialization ────────────────────────────────────────────────────────────
|
|
1353
1335
|
/** @inheritDoc — SDK-derived (Token.fromCBOR → latestTransaction.calculateStateHash().imprint). */
|
|
@@ -1431,7 +1413,13 @@ var SphereTokenEngine = class {
|
|
|
1431
1413
|
let submitRejectedCleanly = false;
|
|
1432
1414
|
try {
|
|
1433
1415
|
const { value: response, retried } = await retryTransient(
|
|
1434
|
-
() =>
|
|
1416
|
+
async () => {
|
|
1417
|
+
const answer = await this.deps.client.submitCertificationRequest(certificationData);
|
|
1418
|
+
if (String(answer.status) === String(import_CertificationResponse.CertificationStatus.SERVICE_NOT_READY)) {
|
|
1419
|
+
throw new TransientSubmitAnswer(String(answer.status));
|
|
1420
|
+
}
|
|
1421
|
+
return answer;
|
|
1422
|
+
},
|
|
1435
1423
|
signal,
|
|
1436
1424
|
this.deps.proofPollIntervalMs ?? DEFAULT_PROOF_POLL_INTERVAL_MS
|
|
1437
1425
|
);
|
|
@@ -1486,8 +1474,6 @@ var SphereTokenEngine = class {
|
|
|
1486
1474
|
}
|
|
1487
1475
|
}
|
|
1488
1476
|
const blob = {
|
|
1489
|
-
v: TOKEN_BLOB_VERSION,
|
|
1490
|
-
network: sdkToken.genesis.networkId.id,
|
|
1491
1477
|
tokenId: import_HexConverter.HexConverter.encode(sdkToken.id.bytes),
|
|
1492
1478
|
token: sdkToken.toCBOR()
|
|
1493
1479
|
};
|