@mysten-incubation/suipay-buyer 0.4.0-dev.0 → 0.4.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/index.d.ts +4 -1
- package/dist/index.js +528 -236
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -990,7 +990,7 @@ declare function createReader(options: PayerReadClientOptions): PayerReadClient;
|
|
|
990
990
|
* prior done result is never lost when capability is unavailable.
|
|
991
991
|
* 5. Derive payment_id_hash / terms_hash.
|
|
992
992
|
* 6. Build the full executable pay transaction (real shared-object versions).
|
|
993
|
-
* 7. Validate-before-sign (
|
|
993
|
+
* 7. Validate-before-sign (intended pay plus the caller's gas authority).
|
|
994
994
|
* 8. Sign, 9. execute, 10. complete(ledger) with terminal ok/ambiguous, settle.
|
|
995
995
|
* x402 refuses before 3 when its offer, gas pins or epoch are missing, skips
|
|
996
996
|
* 4, builds 6 with the offer-pinned sponsor gas, and in place of 9-10
|
|
@@ -1825,6 +1825,9 @@ interface VerifyPreparedSettlementInput {
|
|
|
1825
1825
|
*/
|
|
1826
1826
|
expectedGrantObjectId?: string;
|
|
1827
1827
|
expectedPoolObjectId?: string;
|
|
1828
|
+
/** Independently read network bounds for Epoch / ValidDuring envelopes. */
|
|
1829
|
+
getCurrentEpoch?: () => Promise<bigint | number>;
|
|
1830
|
+
getChainIdentifier?: () => Promise<string>;
|
|
1828
1831
|
}
|
|
1829
1832
|
/**
|
|
1830
1833
|
* Verify a prepared settlement and return it, or throw
|
package/dist/index.js
CHANGED
|
@@ -856,6 +856,9 @@ function verifyOwnerTransaction(input) {
|
|
|
856
856
|
const cmd = commands[i];
|
|
857
857
|
if (cmd.$kind === "MergeCoins") {
|
|
858
858
|
const mc = cmd.MergeCoins;
|
|
859
|
+
if (JSON.stringify(mc.destination) !== JSON.stringify(splitCmd.SplitCoins.coin)) {
|
|
860
|
+
throw new TransactionVerificationError("funding");
|
|
861
|
+
}
|
|
859
862
|
markInputOrResult(mc.destination);
|
|
860
863
|
for (const s of mc.sources) {
|
|
861
864
|
markInputOrResult(s);
|
|
@@ -1732,6 +1735,27 @@ function assertMoveFunction(target, expected) {
|
|
|
1732
1735
|
if (fn !== expected)
|
|
1733
1736
|
throw new TransactionVerificationError("target");
|
|
1734
1737
|
}
|
|
1738
|
+
function assertPreparedGrantScopes(scopes, prepared, submitted = [], assets = TESTNET_ASSETS) {
|
|
1739
|
+
const declared = /* @__PURE__ */ new Set();
|
|
1740
|
+
for (const scope of scopes) {
|
|
1741
|
+
const asset = declaredAsset(scope.asset, assets);
|
|
1742
|
+
if (!asset || declared.has(asset.id))
|
|
1743
|
+
throw new TransactionVerificationError("coinType");
|
|
1744
|
+
declared.add(asset.id);
|
|
1745
|
+
}
|
|
1746
|
+
const seenAssets = /* @__PURE__ */ new Set();
|
|
1747
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
1748
|
+
for (const grant of [...prepared, ...submitted]) {
|
|
1749
|
+
const asset = "coinType" in grant && typeof grant.coinType === "string" && declaredAsset(grant.coinType, assets) || declaredAsset(grant.asset, assets);
|
|
1750
|
+
if (!asset || !declared.has(asset.id))
|
|
1751
|
+
throw new TransactionVerificationError("coinType");
|
|
1752
|
+
if (seenAssets.has(asset.id) || seenIds.has(grant.grantId)) {
|
|
1753
|
+
throw new TransactionVerificationError("grants");
|
|
1754
|
+
}
|
|
1755
|
+
seenAssets.add(asset.id);
|
|
1756
|
+
seenIds.add(grant.grantId);
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1735
1759
|
|
|
1736
1760
|
// ../sdk/dist/buyer/v1/delegated-signers.js
|
|
1737
1761
|
function createAgentsApi(transport) {
|
|
@@ -1831,6 +1855,7 @@ function createAgentsApi(transport) {
|
|
|
1831
1855
|
const created = await create(input);
|
|
1832
1856
|
if (!created.ok)
|
|
1833
1857
|
return created;
|
|
1858
|
+
assertPreparedGrantScopes(input.assetScopes, created.value.grants, created.value.submitted);
|
|
1834
1859
|
const finalized = [];
|
|
1835
1860
|
for (const submitted of created.value.submitted ?? []) {
|
|
1836
1861
|
const fin = await finalizeGrant(created.value.delegatedSignerId, submitted.grantId, submitted.digest);
|
|
@@ -2513,7 +2538,7 @@ function createBuyerControlPlane(options) {
|
|
|
2513
2538
|
var createBuyer = createBuyerControlPlane;
|
|
2514
2539
|
|
|
2515
2540
|
// ../sdk/dist/agent-sdk/delegate-agent.js
|
|
2516
|
-
import { normalizeSuiAddress as
|
|
2541
|
+
import { normalizeSuiAddress as normalizeSuiAddress12 } from "@mysten/sui/utils";
|
|
2517
2542
|
|
|
2518
2543
|
// ../sdk/dist/buyer-control/chain.js
|
|
2519
2544
|
import { bcs as bcs2 } from "@mysten/sui/bcs";
|
|
@@ -2580,7 +2605,30 @@ function createFailoverGrpcClient(options) {
|
|
|
2580
2605
|
const clients = endpoints.map((baseUrl) => new SuiGrpcClient({ network: options.network, baseUrl }));
|
|
2581
2606
|
return wrapFailover(clients, { sleep: endpointRetrySleep });
|
|
2582
2607
|
}
|
|
2583
|
-
var FAILOVER_SERVICES = ["core", "ledgerService"];
|
|
2608
|
+
var FAILOVER_SERVICES = ["core", "ledgerService", "movePackageService"];
|
|
2609
|
+
var UNARY_RESULT_PROPERTIES = ["headers", "response", "status", "trailers"];
|
|
2610
|
+
function isUnaryCall(value) {
|
|
2611
|
+
return "method" in value && "request" in value && "requestHeaders" in value && UNARY_RESULT_PROPERTIES.every((prop) => typeof value[prop]?.then === "function");
|
|
2612
|
+
}
|
|
2613
|
+
function unaryCallWithFailover(first, finished) {
|
|
2614
|
+
const then = finished.then.bind(finished);
|
|
2615
|
+
const properties = /* @__PURE__ */ new Map();
|
|
2616
|
+
return new Proxy(first, {
|
|
2617
|
+
get(target, prop) {
|
|
2618
|
+
if (prop === "then")
|
|
2619
|
+
return then;
|
|
2620
|
+
if (UNARY_RESULT_PROPERTIES.includes(prop)) {
|
|
2621
|
+
let value = properties.get(prop);
|
|
2622
|
+
if (!value) {
|
|
2623
|
+
value = finished.then((call) => call[prop]);
|
|
2624
|
+
properties.set(prop, value);
|
|
2625
|
+
}
|
|
2626
|
+
return value;
|
|
2627
|
+
}
|
|
2628
|
+
return Reflect.get(target, prop, target);
|
|
2629
|
+
}
|
|
2630
|
+
});
|
|
2631
|
+
}
|
|
2584
2632
|
function wrapFailover(clients, options = {}) {
|
|
2585
2633
|
const primary = clients[0];
|
|
2586
2634
|
const attempts = Math.max(1, options.attempts ?? RPC_ATTEMPTS_PER_ENDPOINT);
|
|
@@ -2598,10 +2646,14 @@ function wrapFailover(clients, options = {}) {
|
|
|
2598
2646
|
return (...args) => {
|
|
2599
2647
|
const first = callOn(primary, prop, args);
|
|
2600
2648
|
const attemptsFor = prop === "executeTransaction" ? 1 : attempts;
|
|
2601
|
-
if (first == null || typeof first.then !== "function"
|
|
2649
|
+
if (first == null || typeof first.then !== "function") {
|
|
2602
2650
|
return first;
|
|
2603
2651
|
}
|
|
2604
|
-
|
|
2652
|
+
const promise = typeof first.catch === "function";
|
|
2653
|
+
const unary = !promise && typeof first === "object" && isUnaryCall(first);
|
|
2654
|
+
if (!promise && !unary)
|
|
2655
|
+
return first;
|
|
2656
|
+
const finished = (async () => {
|
|
2605
2657
|
let last;
|
|
2606
2658
|
for (let endpoint = 0; endpoint < clients.length; endpoint++) {
|
|
2607
2659
|
for (let attempt = 0; attempt < attemptsFor; attempt++) {
|
|
@@ -2623,6 +2675,7 @@ function wrapFailover(clients, options = {}) {
|
|
|
2623
2675
|
}
|
|
2624
2676
|
throw last;
|
|
2625
2677
|
})();
|
|
2678
|
+
return unary ? unaryCallWithFailover(first, finished) : finished;
|
|
2626
2679
|
};
|
|
2627
2680
|
}
|
|
2628
2681
|
});
|
|
@@ -3127,6 +3180,38 @@ function createSpendAccountChain(options) {
|
|
|
3127
3180
|
});
|
|
3128
3181
|
const packageId = normalizeSuiAddress3(options.packageId);
|
|
3129
3182
|
const target = (fn) => `${packageId}::${MODULE}::${fn}`;
|
|
3183
|
+
let grantRevokePackageId = null;
|
|
3184
|
+
async function readGrantRevokePackageId() {
|
|
3185
|
+
if (grantRevokePackageId)
|
|
3186
|
+
return grantRevokePackageId;
|
|
3187
|
+
try {
|
|
3188
|
+
const answer = await client.movePackageService.getDatatype({
|
|
3189
|
+
packageId,
|
|
3190
|
+
moduleName: MODULE,
|
|
3191
|
+
name: "GrantRevoked"
|
|
3192
|
+
});
|
|
3193
|
+
const definingId = answer.response?.datatype?.definingId;
|
|
3194
|
+
if (!definingId?.trim()) {
|
|
3195
|
+
logError({
|
|
3196
|
+
scope: "sdk.buyer-control",
|
|
3197
|
+
code: "chain.unavailable",
|
|
3198
|
+
level: "warn",
|
|
3199
|
+
msg: "Grant revoke datatype origin lookup returned no defining id"
|
|
3200
|
+
});
|
|
3201
|
+
return null;
|
|
3202
|
+
}
|
|
3203
|
+
grantRevokePackageId = normalizeSuiAddress3(definingId);
|
|
3204
|
+
return grantRevokePackageId;
|
|
3205
|
+
} catch (err) {
|
|
3206
|
+
logError({
|
|
3207
|
+
scope: "sdk.buyer-control",
|
|
3208
|
+
code: "chain.unavailable",
|
|
3209
|
+
level: "warn",
|
|
3210
|
+
msg: "Grant revoke datatype origin lookup failed"
|
|
3211
|
+
}, err);
|
|
3212
|
+
return null;
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3130
3215
|
async function kindBytes(tx) {
|
|
3131
3216
|
return {
|
|
3132
3217
|
kindBytes: toBase64(await tx.build({ client, onlyTransactionKind: true }))
|
|
@@ -3735,6 +3820,44 @@ function createSpendAccountChain(options) {
|
|
|
3735
3820
|
return null;
|
|
3736
3821
|
}
|
|
3737
3822
|
},
|
|
3823
|
+
readGrantRevokePackageId,
|
|
3824
|
+
async findGrantRevokeTransaction({ ownerAddress, grantObjectId }) {
|
|
3825
|
+
try {
|
|
3826
|
+
const owner = normalizeSuiAddress3(ownerAddress);
|
|
3827
|
+
const grant = normalizeSuiAddress3(grantObjectId);
|
|
3828
|
+
const definingId = await readGrantRevokePackageId();
|
|
3829
|
+
if (!definingId)
|
|
3830
|
+
return null;
|
|
3831
|
+
const eventType = `${definingId}::${MODULE}::GrantRevoked`;
|
|
3832
|
+
let before = null;
|
|
3833
|
+
let inspected = 0;
|
|
3834
|
+
for (let page = 0; page < 8 && inspected < 200; page++) {
|
|
3835
|
+
const result = await client.core.listEvents({
|
|
3836
|
+
filter: { sender: owner },
|
|
3837
|
+
order: "descending",
|
|
3838
|
+
limit: Math.min(50, 200 - inspected),
|
|
3839
|
+
before
|
|
3840
|
+
});
|
|
3841
|
+
for (const event of result.events.slice(0, 200 - inspected)) {
|
|
3842
|
+
inspected++;
|
|
3843
|
+
if (event.eventType !== eventType)
|
|
3844
|
+
continue;
|
|
3845
|
+
const json = event.json;
|
|
3846
|
+
if (typeof json?.grant !== "string" || normalizeSuiAddress3(json.grant) !== grant)
|
|
3847
|
+
continue;
|
|
3848
|
+
const digest = event.transactionDigest.trim();
|
|
3849
|
+
if (digest)
|
|
3850
|
+
return digest;
|
|
3851
|
+
}
|
|
3852
|
+
if (!result.hasNextPage || !result.endCursor || result.endCursor === before)
|
|
3853
|
+
return null;
|
|
3854
|
+
before = result.endCursor;
|
|
3855
|
+
}
|
|
3856
|
+
return null;
|
|
3857
|
+
} catch {
|
|
3858
|
+
return null;
|
|
3859
|
+
}
|
|
3860
|
+
},
|
|
3738
3861
|
async readPolicyBudget({ poolObjectId, onChainPolicyId }) {
|
|
3739
3862
|
try {
|
|
3740
3863
|
const response = await client.core.getDynamicField({
|
|
@@ -4722,8 +4845,8 @@ function createGrpcExclusionRegistryReader(client) {
|
|
|
4722
4845
|
|
|
4723
4846
|
// ../sdk/dist/delegated-signer/payer.js
|
|
4724
4847
|
import { bcs as bcs7 } from "@mysten/sui/bcs";
|
|
4725
|
-
import { Transaction as
|
|
4726
|
-
import { fromBase64 as
|
|
4848
|
+
import { Transaction as Transaction5 } from "@mysten/sui/transactions";
|
|
4849
|
+
import { fromBase64 as fromBase648, normalizeStructTag as normalizeStructTag10, normalizeSuiAddress as normalizeSuiAddress10, toBase64 as toBase645 } from "@mysten/sui/utils";
|
|
4727
4850
|
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
4728
4851
|
|
|
4729
4852
|
// ../sdk/dist/delegated-signer/finality-poll.js
|
|
@@ -4748,186 +4871,9 @@ async function pollFinality(input) {
|
|
|
4748
4871
|
return { status: "timeout" };
|
|
4749
4872
|
}
|
|
4750
4873
|
|
|
4751
|
-
// ../sdk/dist/pay-
|
|
4752
|
-
import {
|
|
4753
|
-
|
|
4754
|
-
// ../core/dist/policy/grant-target.js
|
|
4755
|
-
function normalizeHash(hex) {
|
|
4756
|
-
return hex.replace(/^0x/i, "").toLowerCase();
|
|
4757
|
-
}
|
|
4758
|
-
function grantAuthorityUsable(snapshot) {
|
|
4759
|
-
if (snapshot.status === "paused") {
|
|
4760
|
-
return { ok: false, reason: "grant is paused" };
|
|
4761
|
-
}
|
|
4762
|
-
if (snapshot.status === "revoked") {
|
|
4763
|
-
return { ok: false, reason: "grant is revoked" };
|
|
4764
|
-
}
|
|
4765
|
-
if (snapshot.status === "expired") {
|
|
4766
|
-
return { ok: false, reason: "grant is expired" };
|
|
4767
|
-
}
|
|
4768
|
-
if (snapshot.status !== "active") {
|
|
4769
|
-
return { ok: false, reason: `grant status is ${snapshot.status}` };
|
|
4770
|
-
}
|
|
4771
|
-
if (!snapshot.grantObjectId?.trim()) {
|
|
4772
|
-
return { ok: false, reason: "grant is not finalized (missing grantObjectId)" };
|
|
4773
|
-
}
|
|
4774
|
-
if (!snapshot.poolObjectId?.trim()) {
|
|
4775
|
-
return { ok: false, reason: "poolObjectId is required" };
|
|
4776
|
-
}
|
|
4777
|
-
return {
|
|
4778
|
-
ok: true,
|
|
4779
|
-
grantObjectId: snapshot.grantObjectId,
|
|
4780
|
-
poolObjectId: snapshot.poolObjectId
|
|
4781
|
-
};
|
|
4782
|
-
}
|
|
4783
|
-
function resolveGrantTarget(snapshot, offerTargetHash) {
|
|
4784
|
-
if (!offerTargetHash?.trim()) {
|
|
4785
|
-
return { ok: false, reason: "offer.targetHash is required" };
|
|
4786
|
-
}
|
|
4787
|
-
const wanted = normalizeHash(offerTargetHash);
|
|
4788
|
-
if (!/^[0-9a-f]{64}$/.test(wanted)) {
|
|
4789
|
-
return { ok: false, reason: "offer.targetHash must be 32-byte hex" };
|
|
4790
|
-
}
|
|
4791
|
-
const usable = grantAuthorityUsable(snapshot);
|
|
4792
|
-
if (!usable.ok) {
|
|
4793
|
-
return usable;
|
|
4794
|
-
}
|
|
4795
|
-
const hits = [];
|
|
4796
|
-
for (const policy of snapshot.policies) {
|
|
4797
|
-
if (policy.status !== "active")
|
|
4798
|
-
continue;
|
|
4799
|
-
for (const target of policy.targets) {
|
|
4800
|
-
if (normalizeHash(target.targetHash) === wanted) {
|
|
4801
|
-
hits.push({
|
|
4802
|
-
policyId: policy.policyId,
|
|
4803
|
-
onChainPolicyId: policy.onChainPolicyId,
|
|
4804
|
-
maxPerPayment: target.maxPerPayment
|
|
4805
|
-
});
|
|
4806
|
-
}
|
|
4807
|
-
}
|
|
4808
|
-
}
|
|
4809
|
-
if (hits.length > 1) {
|
|
4810
|
-
return {
|
|
4811
|
-
ok: false,
|
|
4812
|
-
reason: `target hash resolves to ${hits.length} active policies (EPolicyConflict)`
|
|
4813
|
-
};
|
|
4814
|
-
}
|
|
4815
|
-
if (hits.length === 1) {
|
|
4816
|
-
const hit = hits[0];
|
|
4817
|
-
return {
|
|
4818
|
-
ok: true,
|
|
4819
|
-
policyId: hit.policyId,
|
|
4820
|
-
onChainPolicyId: hit.onChainPolicyId,
|
|
4821
|
-
targetHash: wanted,
|
|
4822
|
-
maxPerPayment: hit.maxPerPayment,
|
|
4823
|
-
poolObjectId: usable.poolObjectId,
|
|
4824
|
-
grantObjectId: usable.grantObjectId,
|
|
4825
|
-
coinType: snapshot.coinType,
|
|
4826
|
-
delegateAddress: snapshot.delegateAddress
|
|
4827
|
-
};
|
|
4828
|
-
}
|
|
4829
|
-
return {
|
|
4830
|
-
ok: false,
|
|
4831
|
-
reason: "no active policy in grant snapshot matches offer.targetHash"
|
|
4832
|
-
};
|
|
4833
|
-
}
|
|
4834
|
-
|
|
4835
|
-
// ../sdk/dist/protocol/carrier.js
|
|
4836
|
-
import { fromBase64 as fromBase645, toBase64 as toBase643 } from "@mysten/sui/utils";
|
|
4837
|
-
|
|
4838
|
-
// ../sdk/dist/protocol/auth-params.js
|
|
4839
|
-
var TOKEN = /^[A-Za-z0-9!#$%&'*+\-.^_`|~]+$/;
|
|
4840
|
-
function parseAuthHeader(header) {
|
|
4841
|
-
const trimmed = header.trim();
|
|
4842
|
-
const firstSpace = trimmed.indexOf(" ");
|
|
4843
|
-
if (firstSpace === -1)
|
|
4844
|
-
return null;
|
|
4845
|
-
const scheme = trimmed.slice(0, firstSpace);
|
|
4846
|
-
if (!TOKEN.test(scheme))
|
|
4847
|
-
return null;
|
|
4848
|
-
const params = parseParams(trimmed.slice(firstSpace + 1));
|
|
4849
|
-
return params === null ? null : { scheme, params };
|
|
4850
|
-
}
|
|
4851
|
-
function parseParams(input) {
|
|
4852
|
-
const params = {};
|
|
4853
|
-
let i = 0;
|
|
4854
|
-
const skipSpace = () => {
|
|
4855
|
-
while (i < input.length && (input[i] === " " || input[i] === " "))
|
|
4856
|
-
i++;
|
|
4857
|
-
};
|
|
4858
|
-
skipSpace();
|
|
4859
|
-
while (i < input.length) {
|
|
4860
|
-
const keyStart = i;
|
|
4861
|
-
while (i < input.length && input[i] !== "=")
|
|
4862
|
-
i++;
|
|
4863
|
-
if (i >= input.length)
|
|
4864
|
-
return null;
|
|
4865
|
-
const key = input.slice(keyStart, i).trim();
|
|
4866
|
-
if (!TOKEN.test(key))
|
|
4867
|
-
return null;
|
|
4868
|
-
i++;
|
|
4869
|
-
let value;
|
|
4870
|
-
if (input[i] === '"') {
|
|
4871
|
-
i++;
|
|
4872
|
-
let out = "";
|
|
4873
|
-
let closed = false;
|
|
4874
|
-
while (i < input.length) {
|
|
4875
|
-
const ch = input[i];
|
|
4876
|
-
if (ch === "\\" && i + 1 < input.length) {
|
|
4877
|
-
out += input[i + 1];
|
|
4878
|
-
i += 2;
|
|
4879
|
-
continue;
|
|
4880
|
-
}
|
|
4881
|
-
if (ch === '"') {
|
|
4882
|
-
i++;
|
|
4883
|
-
closed = true;
|
|
4884
|
-
break;
|
|
4885
|
-
}
|
|
4886
|
-
out += ch;
|
|
4887
|
-
i++;
|
|
4888
|
-
}
|
|
4889
|
-
if (!closed)
|
|
4890
|
-
return null;
|
|
4891
|
-
value = out;
|
|
4892
|
-
} else {
|
|
4893
|
-
const start = i;
|
|
4894
|
-
while (i < input.length && input[i] !== ",")
|
|
4895
|
-
i++;
|
|
4896
|
-
value = input.slice(start, i).trim();
|
|
4897
|
-
}
|
|
4898
|
-
params[key] = value;
|
|
4899
|
-
skipSpace();
|
|
4900
|
-
if (i < input.length) {
|
|
4901
|
-
if (input[i] !== ",")
|
|
4902
|
-
return null;
|
|
4903
|
-
i++;
|
|
4904
|
-
skipSpace();
|
|
4905
|
-
}
|
|
4906
|
-
}
|
|
4907
|
-
return params;
|
|
4908
|
-
}
|
|
4909
|
-
|
|
4910
|
-
// ../sdk/dist/protocol/base64url.js
|
|
4911
|
-
function bytesToBase64Url(bytes) {
|
|
4912
|
-
let binary = "";
|
|
4913
|
-
for (const byte of bytes)
|
|
4914
|
-
binary += String.fromCharCode(byte);
|
|
4915
|
-
const base64 = typeof globalThis.btoa === "function" ? globalThis.btoa(binary) : Buffer.from(bytes).toString("base64");
|
|
4916
|
-
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
4917
|
-
}
|
|
4918
|
-
function bytesFromBase64Url(s) {
|
|
4919
|
-
const normalized = s.replace(/-/g, "+").replace(/_/g, "/");
|
|
4920
|
-
const pad = (4 - normalized.length % 4) % 4;
|
|
4921
|
-
const base64 = normalized + "=".repeat(pad);
|
|
4922
|
-
if (typeof globalThis.atob === "function") {
|
|
4923
|
-
const binary = globalThis.atob(base64);
|
|
4924
|
-
const out = new Uint8Array(binary.length);
|
|
4925
|
-
for (let i = 0; i < binary.length; i++)
|
|
4926
|
-
out[i] = binary.charCodeAt(i);
|
|
4927
|
-
return out;
|
|
4928
|
-
}
|
|
4929
|
-
return Uint8Array.from(Buffer.from(base64, "base64"));
|
|
4930
|
-
}
|
|
4874
|
+
// ../sdk/dist/delegated-signer/pay-gas.js
|
|
4875
|
+
import { Transaction as Transaction3 } from "@mysten/sui/transactions";
|
|
4876
|
+
import { fromBase64 as fromBase644, normalizeSuiAddress as normalizeSuiAddress6 } from "@mysten/sui/utils";
|
|
4931
4877
|
|
|
4932
4878
|
// ../sdk/dist/protocol/challenge.js
|
|
4933
4879
|
import { Ed25519PublicKey } from "@mysten/sui/keypairs/ed25519";
|
|
@@ -5014,6 +4960,53 @@ var OMIT_WHEN_ABSENT = /* @__PURE__ */ new Set([
|
|
|
5014
4960
|
...V4_OMIT_WHEN_ABSENT
|
|
5015
4961
|
]);
|
|
5016
4962
|
var BODY_HASH_RE = /^[A-Za-z0-9_-]{43}$/;
|
|
4963
|
+
var CONTROL_CHAR_RE = /[\x00-\x1f\x7f]/;
|
|
4964
|
+
var SIGNED_NUMBER_FIELDS = /* @__PURE__ */ new Set([
|
|
4965
|
+
"decimals",
|
|
4966
|
+
"issuedAt",
|
|
4967
|
+
"expiresAt",
|
|
4968
|
+
"digestVersion",
|
|
4969
|
+
"serviceRevision",
|
|
4970
|
+
"authorizationEpoch",
|
|
4971
|
+
"periodMs",
|
|
4972
|
+
"periodCount",
|
|
4973
|
+
"refundWindowMs",
|
|
4974
|
+
"decideWindowMs",
|
|
4975
|
+
"chainId",
|
|
4976
|
+
"exclusionProtocolVersion"
|
|
4977
|
+
]);
|
|
4978
|
+
function hasValidSignedOfferFields(offer, requireComplete = true) {
|
|
4979
|
+
if (typeof offer !== "object" || offer === null || Array.isArray(offer))
|
|
4980
|
+
return false;
|
|
4981
|
+
const fields = offer;
|
|
4982
|
+
for (const key of SIGNED_FIELDS_V4) {
|
|
4983
|
+
const value = fields[key];
|
|
4984
|
+
if (value === void 0) {
|
|
4985
|
+
if (requireComplete && SIGNED_FIELDS_V1.includes(key))
|
|
4986
|
+
return false;
|
|
4987
|
+
continue;
|
|
4988
|
+
}
|
|
4989
|
+
if (SIGNED_NUMBER_FIELDS.has(key)) {
|
|
4990
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0)
|
|
4991
|
+
return false;
|
|
4992
|
+
if (key === "digestVersion" && (value < 1 || value > 4))
|
|
4993
|
+
return false;
|
|
4994
|
+
} else if (key === "refundable") {
|
|
4995
|
+
if (typeof value !== "boolean")
|
|
4996
|
+
return false;
|
|
4997
|
+
} else if (key === "acceptedRails") {
|
|
4998
|
+
if (!Array.isArray(value))
|
|
4999
|
+
return false;
|
|
5000
|
+
for (const rail of value) {
|
|
5001
|
+
if (typeof rail !== "string" || CONTROL_CHAR_RE.test(rail) || rail.includes(","))
|
|
5002
|
+
return false;
|
|
5003
|
+
}
|
|
5004
|
+
} else if (typeof value !== "string" || CONTROL_CHAR_RE.test(value)) {
|
|
5005
|
+
return false;
|
|
5006
|
+
}
|
|
5007
|
+
}
|
|
5008
|
+
return true;
|
|
5009
|
+
}
|
|
5017
5010
|
var CONTENT_TYPE_RE = /^[a-z0-9!#$%&'*+.^_`|~-]+\/[a-z0-9!#$%&'*+.^_`|~-]+(?:; ?[a-z0-9!#$%&'*+.^_`|~-]+=(?:[a-zA-Z0-9!#$%&'*+.^_`|~-]+|"[^"\n\r]*"))*$/;
|
|
5018
5011
|
function isBodyHash(value) {
|
|
5019
5012
|
return typeof value === "string" && BODY_HASH_RE.test(value);
|
|
@@ -5192,6 +5185,8 @@ function toRawEd25519PublicKey(key) {
|
|
|
5192
5185
|
throw new Error("unsupported Ed25519 public key representation");
|
|
5193
5186
|
}
|
|
5194
5187
|
function verifyOfferSig(offer, publicKey) {
|
|
5188
|
+
if (!hasValidSignedOfferFields(offer, false))
|
|
5189
|
+
return Promise.resolve(false);
|
|
5195
5190
|
if (!offer.sig || typeof offer.sig !== "string")
|
|
5196
5191
|
return Promise.resolve(false);
|
|
5197
5192
|
if (!offer.digest || typeof offer.digest !== "string" || !offer.digest.trim() || offer.digest !== offer.digest.trim()) {
|
|
@@ -5266,6 +5261,275 @@ function addressBalanceGasExpiration(input) {
|
|
|
5266
5261
|
};
|
|
5267
5262
|
}
|
|
5268
5263
|
|
|
5264
|
+
// ../sdk/dist/delegated-signer/pay-gas.js
|
|
5265
|
+
var DEFAULT_GAS_BUDGET = 10000000n;
|
|
5266
|
+
var DEFAULT_GAS_PRICE = 1000n;
|
|
5267
|
+
var X402_EXPIRATION_EPOCHS = 32n;
|
|
5268
|
+
async function readChainBound(read) {
|
|
5269
|
+
try {
|
|
5270
|
+
return await read();
|
|
5271
|
+
} catch (cause) {
|
|
5272
|
+
if (cause instanceof SuiPayError)
|
|
5273
|
+
throw cause;
|
|
5274
|
+
throw SuiPayError.of("chain.unavailable", "not_charged", {
|
|
5275
|
+
detail: "the pre-sign chain read is unavailable; no signature was produced"
|
|
5276
|
+
}, { cause });
|
|
5277
|
+
}
|
|
5278
|
+
}
|
|
5279
|
+
async function readPayExpirationPolicy(txBytes, readers) {
|
|
5280
|
+
const expiration = Transaction3.from(fromBase644(txBytes)).getData().expiration;
|
|
5281
|
+
if (expiration.$kind === "None")
|
|
5282
|
+
return void 0;
|
|
5283
|
+
if (!readers.getCurrentEpoch)
|
|
5284
|
+
throw new Error("a trusted current epoch is required");
|
|
5285
|
+
if (expiration.$kind !== "ValidDuring") {
|
|
5286
|
+
return { currentEpoch: BigInt(await readChainBound(readers.getCurrentEpoch)) };
|
|
5287
|
+
}
|
|
5288
|
+
if (!readers.getChainIdentifier)
|
|
5289
|
+
throw new Error("a trusted chain identifier is required");
|
|
5290
|
+
const [currentEpoch, chainIdentifier] = await Promise.all([
|
|
5291
|
+
readChainBound(readers.getCurrentEpoch),
|
|
5292
|
+
readChainBound(readers.getChainIdentifier)
|
|
5293
|
+
]);
|
|
5294
|
+
return { currentEpoch: BigInt(currentEpoch), chainIdentifier };
|
|
5295
|
+
}
|
|
5296
|
+
function assertPayGas(data, delegate, policy = {}) {
|
|
5297
|
+
const actual = data.gasData;
|
|
5298
|
+
const agent = normalizeSuiAddress6(delegate);
|
|
5299
|
+
if (!actual.owner)
|
|
5300
|
+
throw new Error("transaction gas owner is missing");
|
|
5301
|
+
const owner = normalizeSuiAddress6(actual.owner);
|
|
5302
|
+
const pinned = policy.gas;
|
|
5303
|
+
if (policy.mode !== void 0 && policy.mode !== "agent" && policy.mode !== "sponsored") {
|
|
5304
|
+
throw new Error("transaction gas policy mode is invalid");
|
|
5305
|
+
}
|
|
5306
|
+
if (policy.mode === "agent") {
|
|
5307
|
+
if (!pinned)
|
|
5308
|
+
throw new Error("agent gas requires caller-owned gas inputs");
|
|
5309
|
+
} else if (owner === agent) {
|
|
5310
|
+
throw new Error("sponsored transaction gas owner must not be the delegate");
|
|
5311
|
+
}
|
|
5312
|
+
if (pinned) {
|
|
5313
|
+
const expectedOwner = normalizeSuiAddress6(pinned.owner ?? delegate);
|
|
5314
|
+
const samePayment = actual.payment.length === pinned.payment.length && pinned.payment.every((ref, i) => {
|
|
5315
|
+
const got = actual.payment[i];
|
|
5316
|
+
return normalizeSuiAddress6(got.objectId) === normalizeSuiAddress6(ref.objectId) && got.version === String(ref.version) && got.digest === ref.digest;
|
|
5317
|
+
});
|
|
5318
|
+
if (owner !== expectedOwner || actual.budget !== String(pinned.budget ?? DEFAULT_GAS_BUDGET) || actual.price !== String(pinned.price ?? DEFAULT_GAS_PRICE) || !samePayment) {
|
|
5319
|
+
throw new Error("transaction gas does not match the caller gas inputs");
|
|
5320
|
+
}
|
|
5321
|
+
}
|
|
5322
|
+
const expiration = data.expiration;
|
|
5323
|
+
const validity = policy.expiration;
|
|
5324
|
+
if (expiration.$kind === "None") {
|
|
5325
|
+
if (!actual.payment.length || validity?.requireBounded) {
|
|
5326
|
+
throw new Error("transaction gas requires bounded expiration");
|
|
5327
|
+
}
|
|
5328
|
+
return;
|
|
5329
|
+
}
|
|
5330
|
+
if (!validity || validity.currentEpoch < 0n) {
|
|
5331
|
+
throw new Error("transaction expiration has no trusted epoch bound");
|
|
5332
|
+
}
|
|
5333
|
+
const now = validity.currentEpoch;
|
|
5334
|
+
if (expiration.$kind === "Epoch") {
|
|
5335
|
+
const epoch = BigInt(expiration.Epoch);
|
|
5336
|
+
if (!actual.payment.length || epoch < now || epoch > now + X402_EXPIRATION_EPOCHS) {
|
|
5337
|
+
throw new Error("transaction epoch expiration is outside the allowed window");
|
|
5338
|
+
}
|
|
5339
|
+
return;
|
|
5340
|
+
}
|
|
5341
|
+
const window = expiration.ValidDuring;
|
|
5342
|
+
if (!validity.chainIdentifier || window.chain !== validity.chainIdentifier || window.minEpoch === null || window.maxEpoch === null || window.minTimestamp !== null || window.maxTimestamp !== null) {
|
|
5343
|
+
throw new Error("transaction validity does not match the trusted chain window");
|
|
5344
|
+
}
|
|
5345
|
+
const min = BigInt(window.minEpoch);
|
|
5346
|
+
const max = BigInt(window.maxEpoch);
|
|
5347
|
+
if (min > now || max < now || max > now + ADDRESS_BALANCE_VALIDITY_EPOCHS || max - min > ADDRESS_BALANCE_VALIDITY_EPOCHS) {
|
|
5348
|
+
throw new Error("transaction validity is outside the allowed epoch window");
|
|
5349
|
+
}
|
|
5350
|
+
}
|
|
5351
|
+
|
|
5352
|
+
// ../sdk/dist/pay-operation/operation.js
|
|
5353
|
+
import { normalizeStructTag as normalizeStructTag9, normalizeSuiAddress as normalizeSuiAddress7 } from "@mysten/sui/utils";
|
|
5354
|
+
|
|
5355
|
+
// ../core/dist/policy/grant-target.js
|
|
5356
|
+
function normalizeHash(hex) {
|
|
5357
|
+
return hex.replace(/^0x/i, "").toLowerCase();
|
|
5358
|
+
}
|
|
5359
|
+
function grantAuthorityUsable(snapshot) {
|
|
5360
|
+
if (snapshot.status === "paused") {
|
|
5361
|
+
return { ok: false, reason: "grant is paused" };
|
|
5362
|
+
}
|
|
5363
|
+
if (snapshot.status === "revoked") {
|
|
5364
|
+
return { ok: false, reason: "grant is revoked" };
|
|
5365
|
+
}
|
|
5366
|
+
if (snapshot.status === "expired") {
|
|
5367
|
+
return { ok: false, reason: "grant is expired" };
|
|
5368
|
+
}
|
|
5369
|
+
if (snapshot.status !== "active") {
|
|
5370
|
+
return { ok: false, reason: `grant status is ${snapshot.status}` };
|
|
5371
|
+
}
|
|
5372
|
+
if (!snapshot.grantObjectId?.trim()) {
|
|
5373
|
+
return { ok: false, reason: "grant is not finalized (missing grantObjectId)" };
|
|
5374
|
+
}
|
|
5375
|
+
if (!snapshot.poolObjectId?.trim()) {
|
|
5376
|
+
return { ok: false, reason: "poolObjectId is required" };
|
|
5377
|
+
}
|
|
5378
|
+
return {
|
|
5379
|
+
ok: true,
|
|
5380
|
+
grantObjectId: snapshot.grantObjectId,
|
|
5381
|
+
poolObjectId: snapshot.poolObjectId
|
|
5382
|
+
};
|
|
5383
|
+
}
|
|
5384
|
+
function resolveGrantTarget(snapshot, offerTargetHash) {
|
|
5385
|
+
if (!offerTargetHash?.trim()) {
|
|
5386
|
+
return { ok: false, reason: "offer.targetHash is required" };
|
|
5387
|
+
}
|
|
5388
|
+
const wanted = normalizeHash(offerTargetHash);
|
|
5389
|
+
if (!/^[0-9a-f]{64}$/.test(wanted)) {
|
|
5390
|
+
return { ok: false, reason: "offer.targetHash must be 32-byte hex" };
|
|
5391
|
+
}
|
|
5392
|
+
const usable = grantAuthorityUsable(snapshot);
|
|
5393
|
+
if (!usable.ok) {
|
|
5394
|
+
return usable;
|
|
5395
|
+
}
|
|
5396
|
+
const hits = [];
|
|
5397
|
+
for (const policy of snapshot.policies) {
|
|
5398
|
+
if (policy.status !== "active")
|
|
5399
|
+
continue;
|
|
5400
|
+
for (const target of policy.targets) {
|
|
5401
|
+
if (normalizeHash(target.targetHash) === wanted) {
|
|
5402
|
+
hits.push({
|
|
5403
|
+
policyId: policy.policyId,
|
|
5404
|
+
onChainPolicyId: policy.onChainPolicyId,
|
|
5405
|
+
maxPerPayment: target.maxPerPayment
|
|
5406
|
+
});
|
|
5407
|
+
}
|
|
5408
|
+
}
|
|
5409
|
+
}
|
|
5410
|
+
if (hits.length > 1) {
|
|
5411
|
+
return {
|
|
5412
|
+
ok: false,
|
|
5413
|
+
reason: `target hash resolves to ${hits.length} active policies (EPolicyConflict)`
|
|
5414
|
+
};
|
|
5415
|
+
}
|
|
5416
|
+
if (hits.length === 1) {
|
|
5417
|
+
const hit = hits[0];
|
|
5418
|
+
return {
|
|
5419
|
+
ok: true,
|
|
5420
|
+
policyId: hit.policyId,
|
|
5421
|
+
onChainPolicyId: hit.onChainPolicyId,
|
|
5422
|
+
targetHash: wanted,
|
|
5423
|
+
maxPerPayment: hit.maxPerPayment,
|
|
5424
|
+
poolObjectId: usable.poolObjectId,
|
|
5425
|
+
grantObjectId: usable.grantObjectId,
|
|
5426
|
+
coinType: snapshot.coinType,
|
|
5427
|
+
delegateAddress: snapshot.delegateAddress
|
|
5428
|
+
};
|
|
5429
|
+
}
|
|
5430
|
+
return {
|
|
5431
|
+
ok: false,
|
|
5432
|
+
reason: "no active policy in grant snapshot matches offer.targetHash"
|
|
5433
|
+
};
|
|
5434
|
+
}
|
|
5435
|
+
|
|
5436
|
+
// ../sdk/dist/protocol/carrier.js
|
|
5437
|
+
import { fromBase64 as fromBase646, toBase64 as toBase643 } from "@mysten/sui/utils";
|
|
5438
|
+
|
|
5439
|
+
// ../sdk/dist/protocol/auth-params.js
|
|
5440
|
+
var TOKEN = /^[A-Za-z0-9!#$%&'*+\-.^_`|~]+$/;
|
|
5441
|
+
function parseAuthHeader(header) {
|
|
5442
|
+
const trimmed = header.trim();
|
|
5443
|
+
const firstSpace = trimmed.indexOf(" ");
|
|
5444
|
+
if (firstSpace === -1)
|
|
5445
|
+
return null;
|
|
5446
|
+
const scheme = trimmed.slice(0, firstSpace);
|
|
5447
|
+
if (!TOKEN.test(scheme))
|
|
5448
|
+
return null;
|
|
5449
|
+
const params = parseParams(trimmed.slice(firstSpace + 1));
|
|
5450
|
+
return params === null ? null : { scheme, params };
|
|
5451
|
+
}
|
|
5452
|
+
function parseParams(input) {
|
|
5453
|
+
const params = {};
|
|
5454
|
+
let i = 0;
|
|
5455
|
+
const skipSpace = () => {
|
|
5456
|
+
while (i < input.length && (input[i] === " " || input[i] === " "))
|
|
5457
|
+
i++;
|
|
5458
|
+
};
|
|
5459
|
+
skipSpace();
|
|
5460
|
+
while (i < input.length) {
|
|
5461
|
+
const keyStart = i;
|
|
5462
|
+
while (i < input.length && input[i] !== "=")
|
|
5463
|
+
i++;
|
|
5464
|
+
if (i >= input.length)
|
|
5465
|
+
return null;
|
|
5466
|
+
const key = input.slice(keyStart, i).trim();
|
|
5467
|
+
if (!TOKEN.test(key))
|
|
5468
|
+
return null;
|
|
5469
|
+
i++;
|
|
5470
|
+
let value;
|
|
5471
|
+
if (input[i] === '"') {
|
|
5472
|
+
i++;
|
|
5473
|
+
let out = "";
|
|
5474
|
+
let closed = false;
|
|
5475
|
+
while (i < input.length) {
|
|
5476
|
+
const ch = input[i];
|
|
5477
|
+
if (ch === "\\" && i + 1 < input.length) {
|
|
5478
|
+
out += input[i + 1];
|
|
5479
|
+
i += 2;
|
|
5480
|
+
continue;
|
|
5481
|
+
}
|
|
5482
|
+
if (ch === '"') {
|
|
5483
|
+
i++;
|
|
5484
|
+
closed = true;
|
|
5485
|
+
break;
|
|
5486
|
+
}
|
|
5487
|
+
out += ch;
|
|
5488
|
+
i++;
|
|
5489
|
+
}
|
|
5490
|
+
if (!closed)
|
|
5491
|
+
return null;
|
|
5492
|
+
value = out;
|
|
5493
|
+
} else {
|
|
5494
|
+
const start = i;
|
|
5495
|
+
while (i < input.length && input[i] !== ",")
|
|
5496
|
+
i++;
|
|
5497
|
+
value = input.slice(start, i).trim();
|
|
5498
|
+
}
|
|
5499
|
+
params[key] = value;
|
|
5500
|
+
skipSpace();
|
|
5501
|
+
if (i < input.length) {
|
|
5502
|
+
if (input[i] !== ",")
|
|
5503
|
+
return null;
|
|
5504
|
+
i++;
|
|
5505
|
+
skipSpace();
|
|
5506
|
+
}
|
|
5507
|
+
}
|
|
5508
|
+
return params;
|
|
5509
|
+
}
|
|
5510
|
+
|
|
5511
|
+
// ../sdk/dist/protocol/base64url.js
|
|
5512
|
+
function bytesToBase64Url(bytes) {
|
|
5513
|
+
let binary = "";
|
|
5514
|
+
for (const byte of bytes)
|
|
5515
|
+
binary += String.fromCharCode(byte);
|
|
5516
|
+
const base64 = typeof globalThis.btoa === "function" ? globalThis.btoa(binary) : Buffer.from(bytes).toString("base64");
|
|
5517
|
+
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
5518
|
+
}
|
|
5519
|
+
function bytesFromBase64Url(s) {
|
|
5520
|
+
const normalized = s.replace(/-/g, "+").replace(/_/g, "/");
|
|
5521
|
+
const pad = (4 - normalized.length % 4) % 4;
|
|
5522
|
+
const base64 = normalized + "=".repeat(pad);
|
|
5523
|
+
if (typeof globalThis.atob === "function") {
|
|
5524
|
+
const binary = globalThis.atob(base64);
|
|
5525
|
+
const out = new Uint8Array(binary.length);
|
|
5526
|
+
for (let i = 0; i < binary.length; i++)
|
|
5527
|
+
out[i] = binary.charCodeAt(i);
|
|
5528
|
+
return out;
|
|
5529
|
+
}
|
|
5530
|
+
return Uint8Array.from(Buffer.from(base64, "base64"));
|
|
5531
|
+
}
|
|
5532
|
+
|
|
5269
5533
|
// ../sdk/dist/protocol/mpp.js
|
|
5270
5534
|
function offerToBase64Url(offer) {
|
|
5271
5535
|
return bytesToBase64Url(new TextEncoder().encode(JSON.stringify(offer)));
|
|
@@ -5901,12 +6165,12 @@ function decodeReceipt(header) {
|
|
|
5901
6165
|
}
|
|
5902
6166
|
|
|
5903
6167
|
// ../sdk/dist/protocol/x402.js
|
|
5904
|
-
import { fromBase64 as
|
|
6168
|
+
import { fromBase64 as fromBase645, toBase64 as toBase642 } from "@mysten/sui/utils";
|
|
5905
6169
|
function utf8ToBase64(text) {
|
|
5906
6170
|
return toBase642(new TextEncoder().encode(text));
|
|
5907
6171
|
}
|
|
5908
6172
|
function base64ToUtf8(value) {
|
|
5909
|
-
return new TextDecoder().decode(
|
|
6173
|
+
return new TextDecoder().decode(fromBase645(value));
|
|
5910
6174
|
}
|
|
5911
6175
|
var X402_VERSION = 2;
|
|
5912
6176
|
var X402_SCHEME = "exact";
|
|
@@ -6237,7 +6501,7 @@ async function readChallenge(res, dialect, opts) {
|
|
|
6237
6501
|
const headerVal = res.headers.get(X402_CHALLENGE_HEADER);
|
|
6238
6502
|
if (headerVal) {
|
|
6239
6503
|
try {
|
|
6240
|
-
const parsed = JSON.parse(new TextDecoder().decode(
|
|
6504
|
+
const parsed = JSON.parse(new TextDecoder().decode(fromBase646(headerVal)));
|
|
6241
6505
|
const offer = decodeChallenge2(parsed, opts);
|
|
6242
6506
|
if (offer)
|
|
6243
6507
|
return offer;
|
|
@@ -6826,7 +7090,7 @@ async function resolvePayment(input, deps) {
|
|
|
6826
7090
|
}
|
|
6827
7091
|
let packageMatches;
|
|
6828
7092
|
try {
|
|
6829
|
-
packageMatches =
|
|
7093
|
+
packageMatches = normalizeSuiAddress7(offer.packageId) === normalizeSuiAddress7(packageId);
|
|
6830
7094
|
} catch {
|
|
6831
7095
|
packageMatches = false;
|
|
6832
7096
|
}
|
|
@@ -6873,7 +7137,7 @@ async function resolvePayment(input, deps) {
|
|
|
6873
7137
|
if (!identity) {
|
|
6874
7138
|
return failedWith(PAY_OPERATION_ERROR_CODES.BUILD_FAILED, "guarded offer carries no valid registry identity", challengeId);
|
|
6875
7139
|
}
|
|
6876
|
-
if (
|
|
7140
|
+
if (normalizeSuiAddress7(identity.packageId) !== normalizeSuiAddress7(offer.packageId)) {
|
|
6877
7141
|
return failedWith(PAY_OPERATION_ERROR_CODES.BUILD_FAILED, `guarded registry identity package ${identity.packageId} does not match offer package ${offer.packageId}`, challengeId);
|
|
6878
7142
|
}
|
|
6879
7143
|
if (!resolveExclusionRegistry2) {
|
|
@@ -7068,8 +7332,8 @@ function validateAmount(offer, resolved) {
|
|
|
7068
7332
|
import { randomBytes } from "crypto";
|
|
7069
7333
|
import { bcs as bcs5 } from "@mysten/sui/bcs";
|
|
7070
7334
|
import { isValidPersonalMessageSignature, verifyPersonalMessageSignature } from "@mysten/sui/verify";
|
|
7071
|
-
import { fromBase64 as
|
|
7072
|
-
import { Transaction as
|
|
7335
|
+
import { fromBase64 as fromBase647, normalizeSuiAddress as normalizeSuiAddress8, toBase64 as toBase644 } from "@mysten/sui/utils";
|
|
7336
|
+
import { Transaction as Transaction4 } from "@mysten/sui/transactions";
|
|
7073
7337
|
var SPONSOR_PERSONAL_MESSAGE_DOMAIN = "suipay:sponsor-personal-message:v1";
|
|
7074
7338
|
function encodeSponsorPersonalMessagePayload(payload) {
|
|
7075
7339
|
if (payload.domain !== SPONSOR_PERSONAL_MESSAGE_DOMAIN) {
|
|
@@ -7092,17 +7356,17 @@ function encodeSponsorPersonalMessagePayload(payload) {
|
|
|
7092
7356
|
push(bcs5.vector(bcs5.u8()).serialize([...Buffer.from(payload.domain, "utf8")]).toBytes());
|
|
7093
7357
|
push(bcs5.vector(bcs5.u8()).serialize([...Buffer.from(payload.nonce, "utf8")]).toBytes());
|
|
7094
7358
|
push(bcs5.u64().serialize(BigInt(payload.expiryMs)).toBytes());
|
|
7095
|
-
push(bcs5.Address.serialize(
|
|
7096
|
-
push(bcs5.Address.serialize(
|
|
7097
|
-
push(bcs5.Address.serialize(
|
|
7359
|
+
push(bcs5.Address.serialize(normalizeSuiAddress8(payload.delegate)).toBytes());
|
|
7360
|
+
push(bcs5.Address.serialize(normalizeSuiAddress8(payload.poolId)).toBytes());
|
|
7361
|
+
push(bcs5.Address.serialize(normalizeSuiAddress8(payload.grantId)).toBytes());
|
|
7098
7362
|
push(bcs5.vector(bcs5.u8()).serialize([...Buffer.from(payload.network, "utf8")]).toBytes());
|
|
7099
|
-
push(bcs5.Address.serialize(
|
|
7363
|
+
push(bcs5.Address.serialize(normalizeSuiAddress8(payload.packageId)).toBytes());
|
|
7100
7364
|
push(bcs5.vector(bcs5.u8()).serialize([...Buffer.from(payload.requestId, "utf8")]).toBytes());
|
|
7101
7365
|
push(bcs5.vector(bcs5.u8()).serialize([...payload.txKindHash]).toBytes());
|
|
7102
7366
|
return Buffer.concat(parts.map((p) => Buffer.from(p)));
|
|
7103
7367
|
}
|
|
7104
7368
|
function hashTransactionKindBytes(kindBytes) {
|
|
7105
|
-
const raw = typeof kindBytes === "string" ?
|
|
7369
|
+
const raw = typeof kindBytes === "string" ? fromBase647(kindBytes) : kindBytes;
|
|
7106
7370
|
return sha256(raw);
|
|
7107
7371
|
}
|
|
7108
7372
|
function buildSponsorPersonalMessagePayload(input) {
|
|
@@ -7110,11 +7374,11 @@ function buildSponsorPersonalMessagePayload(input) {
|
|
|
7110
7374
|
domain: SPONSOR_PERSONAL_MESSAGE_DOMAIN,
|
|
7111
7375
|
nonce: input.nonce,
|
|
7112
7376
|
expiryMs: input.expiryMs,
|
|
7113
|
-
delegate:
|
|
7114
|
-
poolId:
|
|
7115
|
-
grantId:
|
|
7377
|
+
delegate: normalizeSuiAddress8(input.delegate),
|
|
7378
|
+
poolId: normalizeSuiAddress8(input.poolId),
|
|
7379
|
+
grantId: normalizeSuiAddress8(input.grantId),
|
|
7116
7380
|
network: input.network,
|
|
7117
|
-
packageId:
|
|
7381
|
+
packageId: normalizeSuiAddress8(input.packageId),
|
|
7118
7382
|
requestId: input.requestId,
|
|
7119
7383
|
txKindHash: hashTransactionKindBytes(input.transactionKindBytes)
|
|
7120
7384
|
};
|
|
@@ -7272,7 +7536,7 @@ function createOfferKeyResolver(gatewayUrl, options = {}) {
|
|
|
7272
7536
|
import { bcs as bcs6 } from "@mysten/sui/bcs";
|
|
7273
7537
|
import { messageWithIntent } from "@mysten/sui/cryptography";
|
|
7274
7538
|
import { isValidPersonalMessageSignature as isValidPersonalMessageSignature2, verifyPersonalMessageSignature as verifyPersonalMessageSignature2 } from "@mysten/sui/verify";
|
|
7275
|
-
import { normalizeSuiAddress as
|
|
7539
|
+
import { normalizeSuiAddress as normalizeSuiAddress9 } from "@mysten/sui/utils";
|
|
7276
7540
|
var SIGNED_REQUEST_DOMAIN = "suipay:signed-request:v1";
|
|
7277
7541
|
var BOOTSTRAP_REQUEST_DOMAIN = "suipay:bootstrap-request:v1";
|
|
7278
7542
|
var SIGNED_REQUEST_MAX_AGE_MS = 3e5;
|
|
@@ -7304,7 +7568,7 @@ function encodeBootstrapRequest(payload) {
|
|
|
7304
7568
|
throw new Error(`domain must be ${BOOTSTRAP_REQUEST_DOMAIN}`);
|
|
7305
7569
|
}
|
|
7306
7570
|
const utf8Vec = (s) => bcs6.vector(bcs6.u8()).serialize([...Buffer.from(s, "utf8")]).toBytes();
|
|
7307
|
-
const addr = (a) => bcs6.Address.serialize(
|
|
7571
|
+
const addr = (a) => bcs6.Address.serialize(normalizeSuiAddress9(a)).toBytes();
|
|
7308
7572
|
const parts = [
|
|
7309
7573
|
utf8Vec(payload.domain),
|
|
7310
7574
|
utf8Vec(payload.network),
|
|
@@ -7324,7 +7588,7 @@ function encodeSignedRequest(payload) {
|
|
|
7324
7588
|
throw new Error(`domain must be ${SIGNED_REQUEST_DOMAIN}`);
|
|
7325
7589
|
}
|
|
7326
7590
|
const utf8Vec = (s) => bcs6.vector(bcs6.u8()).serialize([...Buffer.from(s, "utf8")]).toBytes();
|
|
7327
|
-
const addr = (a) => bcs6.Address.serialize(
|
|
7591
|
+
const addr = (a) => bcs6.Address.serialize(normalizeSuiAddress9(a)).toBytes();
|
|
7328
7592
|
const parts = [
|
|
7329
7593
|
utf8Vec(payload.domain),
|
|
7330
7594
|
utf8Vec(payload.network),
|
|
@@ -7763,7 +8027,6 @@ var bootstrapPayerGrants = bootstrapPayerSessions;
|
|
|
7763
8027
|
// ../sdk/dist/delegated-signer/payer.js
|
|
7764
8028
|
var FINALIZATION_ATTEMPTS = 20;
|
|
7765
8029
|
var FINALIZATION_DELAY_MS = 250;
|
|
7766
|
-
var X402_EXPIRATION_EPOCHS = 32n;
|
|
7767
8030
|
var X402_PRESENT_ATTEMPTS = 10;
|
|
7768
8031
|
var X402_PRESENT_DELAY_MS = 1e3;
|
|
7769
8032
|
function delay(ms) {
|
|
@@ -7774,8 +8037,6 @@ function delay(ms) {
|
|
|
7774
8037
|
var SUI_CLOCK2 = "0x6";
|
|
7775
8038
|
var SUI_CLOCK_INITIAL_SHARED_VERSION = "1";
|
|
7776
8039
|
var BROADCAST_UNKNOWN = "broadcast-unknown";
|
|
7777
|
-
var DEFAULT_GAS_BUDGET = 10000000n;
|
|
7778
|
-
var DEFAULT_GAS_PRICE = 1000n;
|
|
7779
8040
|
var DELEGATED_PAY_ERROR_CODES = {
|
|
7780
8041
|
OFFER_SECRET_REQUIRED: "OFFER_SECRET_REQUIRED",
|
|
7781
8042
|
CHALLENGE_TAMPERED: "CHALLENGE_TAMPERED",
|
|
@@ -8079,7 +8340,7 @@ function defaultLog(entry, error) {
|
|
|
8079
8340
|
}
|
|
8080
8341
|
function sameAddress2(a, b) {
|
|
8081
8342
|
try {
|
|
8082
|
-
return
|
|
8343
|
+
return normalizeSuiAddress10(a) === normalizeSuiAddress10(b);
|
|
8083
8344
|
} catch {
|
|
8084
8345
|
return false;
|
|
8085
8346
|
}
|
|
@@ -8141,7 +8402,7 @@ async function resolveSigner(input) {
|
|
|
8141
8402
|
return {
|
|
8142
8403
|
address: kp.getPublicKey().toSuiAddress(),
|
|
8143
8404
|
async signTransaction(txBytes) {
|
|
8144
|
-
const { signature } = await kp.signTransaction(
|
|
8405
|
+
const { signature } = await kp.signTransaction(fromBase648(txBytes));
|
|
8145
8406
|
return signature;
|
|
8146
8407
|
},
|
|
8147
8408
|
async signPersonalMessage(message) {
|
|
@@ -8217,7 +8478,7 @@ async function buildSpendAccountPayKind(input) {
|
|
|
8217
8478
|
}
|
|
8218
8479
|
const target = payMoveCallTarget(input.packageId, "scoped", true, refundable);
|
|
8219
8480
|
const clockVersion = input.clockInitialSharedVersion?.trim() || SUI_CLOCK_INITIAL_SHARED_VERSION;
|
|
8220
|
-
const tx = new
|
|
8481
|
+
const tx = new Transaction5();
|
|
8221
8482
|
tx.setSender(input.delegate);
|
|
8222
8483
|
tx.moveCall({
|
|
8223
8484
|
target,
|
|
@@ -8289,7 +8550,7 @@ async function buildSpendAccountSettleOpenRecipientKind(input) {
|
|
|
8289
8550
|
const guarded = resolveGuardedSettleOfflineInputs(input);
|
|
8290
8551
|
const target = payMoveCallTarget(input.packageId, "open");
|
|
8291
8552
|
const clockVersion = input.clockInitialSharedVersion?.trim() || SUI_CLOCK_INITIAL_SHARED_VERSION;
|
|
8292
|
-
const tx = new
|
|
8553
|
+
const tx = new Transaction5();
|
|
8293
8554
|
tx.setSender(input.delegate);
|
|
8294
8555
|
tx.moveCall({
|
|
8295
8556
|
target,
|
|
@@ -8336,7 +8597,7 @@ async function buildSpendAccountPayTx(input) {
|
|
|
8336
8597
|
throw new Error("agent gas payment objects are required for executable pay");
|
|
8337
8598
|
}
|
|
8338
8599
|
const { kindBytes } = await buildSpendAccountPayKind(input);
|
|
8339
|
-
const tx =
|
|
8600
|
+
const tx = Transaction5.fromKind(fromBase648(kindBytes));
|
|
8340
8601
|
tx.setSender(input.delegate);
|
|
8341
8602
|
tx.setGasOwner(input.gas.owner ?? input.delegate);
|
|
8342
8603
|
tx.setGasBudget(BigInt(input.gas.budget ?? DEFAULT_GAS_BUDGET));
|
|
@@ -8354,7 +8615,7 @@ async function buildSpendAccountSettleOpenRecipientTx(input) {
|
|
|
8354
8615
|
throw new Error("agent gas payment objects are required for executable pay");
|
|
8355
8616
|
}
|
|
8356
8617
|
const { kindBytes } = await buildSpendAccountSettleOpenRecipientKind(input);
|
|
8357
|
-
const tx =
|
|
8618
|
+
const tx = Transaction5.fromKind(fromBase648(kindBytes));
|
|
8358
8619
|
tx.setSender(input.delegate);
|
|
8359
8620
|
tx.setGasOwner(input.gas.owner ?? input.delegate);
|
|
8360
8621
|
tx.setGasBudget(BigInt(input.gas.budget ?? DEFAULT_GAS_BUDGET));
|
|
@@ -8387,7 +8648,7 @@ function readX402GasPin(offer) {
|
|
|
8387
8648
|
}
|
|
8388
8649
|
async function buildSpendAccountX402PayTx(input) {
|
|
8389
8650
|
const { kindBytes } = await buildSpendAccountPayKind(input);
|
|
8390
|
-
const tx =
|
|
8651
|
+
const tx = Transaction5.fromKind(fromBase648(kindBytes));
|
|
8391
8652
|
tx.setSender(input.delegate);
|
|
8392
8653
|
tx.setGasOwner(input.gas.owner);
|
|
8393
8654
|
tx.setGasBudget(input.gas.budget);
|
|
@@ -8423,7 +8684,7 @@ function chainIdentifierReader(client) {
|
|
|
8423
8684
|
function assertPayTransaction(txBytes, expected) {
|
|
8424
8685
|
let data;
|
|
8425
8686
|
try {
|
|
8426
|
-
data =
|
|
8687
|
+
data = Transaction5.from(fromBase648(txBytes)).getData();
|
|
8427
8688
|
} catch {
|
|
8428
8689
|
throw new Error("transaction is not valid Sui transaction bytes");
|
|
8429
8690
|
}
|
|
@@ -8438,13 +8699,13 @@ function assertPayTransaction(txBytes, expected) {
|
|
|
8438
8699
|
if (cmd.$kind !== "MoveCall" || !cmd.MoveCall) {
|
|
8439
8700
|
throw new Error("transaction is not a MoveCall");
|
|
8440
8701
|
}
|
|
8441
|
-
const got = `${
|
|
8702
|
+
const got = `${normalizeSuiAddress10(String(cmd.MoveCall.package))}::${cmd.MoveCall.module}::${cmd.MoveCall.function}`;
|
|
8442
8703
|
if (got !== wanted) {
|
|
8443
8704
|
throw new Error(`transaction does not reconstruct ${wanted}`);
|
|
8444
8705
|
}
|
|
8445
8706
|
let expectedKind;
|
|
8446
8707
|
try {
|
|
8447
|
-
expectedKind =
|
|
8708
|
+
expectedKind = Transaction5.fromKind(fromBase648(expected.kindBytes)).getData();
|
|
8448
8709
|
} catch {
|
|
8449
8710
|
throw new Error("intended pay kind baseline is invalid");
|
|
8450
8711
|
}
|
|
@@ -8470,6 +8731,7 @@ function assertPayTransaction(txBytes, expected) {
|
|
|
8470
8731
|
if (args && args.length !== expectedArgc) {
|
|
8471
8732
|
throw new Error(`pay expects ${expectedArgc} arguments; got ${args.length}`);
|
|
8472
8733
|
}
|
|
8734
|
+
assertPayGas(data, expected.delegate, expected.gas);
|
|
8473
8735
|
}
|
|
8474
8736
|
function asValidatedReceipt(value) {
|
|
8475
8737
|
if (!value || typeof value !== "object")
|
|
@@ -9265,8 +9527,19 @@ async function payDelegatedSpendAccount(args) {
|
|
|
9265
9527
|
}
|
|
9266
9528
|
}
|
|
9267
9529
|
try {
|
|
9268
|
-
assertPayTransaction(txBytes,
|
|
9530
|
+
assertPayTransaction(txBytes, {
|
|
9531
|
+
...expectedPay,
|
|
9532
|
+
gas: {
|
|
9533
|
+
mode: gasMode,
|
|
9534
|
+
...gasMode === "agent" ? { gas: deps.gas } : {},
|
|
9535
|
+
expiration: await readPayExpirationPolicy(txBytes, deps)
|
|
9536
|
+
}
|
|
9537
|
+
});
|
|
9269
9538
|
} catch (err) {
|
|
9539
|
+
if (err instanceof SuiPayError && err.code === "chain.unavailable") {
|
|
9540
|
+
logInternal(log, { code: "chain.unavailable", msg: "pre-sign chain read failed" }, err);
|
|
9541
|
+
return abortBeforeSign("PREPARED_VERIFY_UNAVAILABLE", PUBLIC_DETAIL.PREPARED_VERIFY_UNAVAILABLE);
|
|
9542
|
+
}
|
|
9270
9543
|
logInternal(log, { code: "client.tx_mismatch", msg: "pre-sign pay validation failed" }, err);
|
|
9271
9544
|
return abortBeforeSign(gasMode === "sponsored" ? "SPONSORED_TX_MISMATCH" : "TX_MISMATCH", gasMode === "sponsored" ? PUBLIC_DETAIL.SPONSORED_TX_MISMATCH : PUBLIC_DETAIL.TX_MISMATCH);
|
|
9272
9545
|
}
|
|
@@ -9533,7 +9806,18 @@ async function payX402Reserved(ctx) {
|
|
|
9533
9806
|
return ctx.abort("BUILD_FAILED", PUBLIC_DETAIL.BUILD_FAILED);
|
|
9534
9807
|
}
|
|
9535
9808
|
try {
|
|
9536
|
-
assertPayTransaction(txBytes,
|
|
9809
|
+
assertPayTransaction(txBytes, {
|
|
9810
|
+
...ctx.expected,
|
|
9811
|
+
gas: {
|
|
9812
|
+
mode: "sponsored",
|
|
9813
|
+
gas: ctx.buildInput.gas,
|
|
9814
|
+
expiration: {
|
|
9815
|
+
currentEpoch: ctx.buildInput.currentEpoch,
|
|
9816
|
+
chainIdentifier: ctx.buildInput.chainIdentifier,
|
|
9817
|
+
requireBounded: true
|
|
9818
|
+
}
|
|
9819
|
+
}
|
|
9820
|
+
});
|
|
9537
9821
|
} catch (err) {
|
|
9538
9822
|
logInternal(log, { code: "client.tx_mismatch", msg: "pre-sign x402 pay validation failed" }, err);
|
|
9539
9823
|
return ctx.abort("TX_MISMATCH", PUBLIC_DETAIL.TX_MISMATCH);
|
|
@@ -9723,7 +10007,7 @@ function payMoveCallTarget(packageId, accessMode = "scoped", _guarded = false, r
|
|
|
9723
10007
|
accessMode: accessMode === "open" ? "open" : "scoped",
|
|
9724
10008
|
refundable
|
|
9725
10009
|
});
|
|
9726
|
-
return `${
|
|
10010
|
+
return `${normalizeSuiAddress10(packageId)}::spend_account::${fn}`;
|
|
9727
10011
|
}
|
|
9728
10012
|
function resolveGuardedSettleOfflineInputs(input) {
|
|
9729
10013
|
const core = [input.exclusionDirectoryId, input.recipientRegistryId, input.expiresAtMs];
|
|
@@ -9799,9 +10083,9 @@ function createMemoryLedger() {
|
|
|
9799
10083
|
}
|
|
9800
10084
|
|
|
9801
10085
|
// ../sdk/dist/agent-sdk/verify-prepared-settlement.js
|
|
9802
|
-
import { normalizeSuiAddress as
|
|
9803
|
-
import { Transaction as
|
|
9804
|
-
import { fromBase64 as
|
|
10086
|
+
import { normalizeSuiAddress as normalizeSuiAddress11 } from "@mysten/sui/utils";
|
|
10087
|
+
import { Transaction as Transaction6 } from "@mysten/sui/transactions";
|
|
10088
|
+
import { fromBase64 as fromBase649 } from "@mysten/sui/utils";
|
|
9805
10089
|
|
|
9806
10090
|
// ../sdk/dist/protocol/prepared-settlement.js
|
|
9807
10091
|
var PREPARED_SETTLEMENT_VERSION = 1;
|
|
@@ -9890,7 +10174,7 @@ function reject(field, message, cause) {
|
|
|
9890
10174
|
}
|
|
9891
10175
|
function sameAddress3(a, b) {
|
|
9892
10176
|
try {
|
|
9893
|
-
return
|
|
10177
|
+
return normalizeSuiAddress11(a) === normalizeSuiAddress11(b);
|
|
9894
10178
|
} catch {
|
|
9895
10179
|
return false;
|
|
9896
10180
|
}
|
|
@@ -9901,7 +10185,7 @@ function sameCoinType(a, b) {
|
|
|
9901
10185
|
if (pkg === void 0 || rest.length !== 2)
|
|
9902
10186
|
return value.trim();
|
|
9903
10187
|
try {
|
|
9904
|
-
return `${
|
|
10188
|
+
return `${normalizeSuiAddress11(pkg)}::${rest.join("::")}`;
|
|
9905
10189
|
} catch {
|
|
9906
10190
|
return value.trim();
|
|
9907
10191
|
}
|
|
@@ -9926,7 +10210,7 @@ async function verifyPreparedPayment(input) {
|
|
|
9926
10210
|
}
|
|
9927
10211
|
let data;
|
|
9928
10212
|
try {
|
|
9929
|
-
data =
|
|
10213
|
+
data = Transaction6.from(fromBase649(prepared.transactionBytes)).getData();
|
|
9930
10214
|
} catch {
|
|
9931
10215
|
reject("transactionBytes", "prepared transaction bytes are not a Sui transaction");
|
|
9932
10216
|
}
|
|
@@ -10041,9 +10325,15 @@ async function verifyPreparedPayment(input) {
|
|
|
10041
10325
|
kindBytes: rebuilt,
|
|
10042
10326
|
accessMode: prepared.accessMode,
|
|
10043
10327
|
recipient: prepared.recipient,
|
|
10044
|
-
refundable: offer.refundable === true
|
|
10328
|
+
refundable: offer.refundable === true,
|
|
10329
|
+
gas: {
|
|
10330
|
+
mode: "sponsored",
|
|
10331
|
+
expiration: await readPayExpirationPolicy(prepared.transactionBytes, input)
|
|
10332
|
+
}
|
|
10045
10333
|
});
|
|
10046
10334
|
} catch (err) {
|
|
10335
|
+
if (err instanceof SuiPayError && err.code === "chain.unavailable")
|
|
10336
|
+
throw err;
|
|
10047
10337
|
reject("transactionBytes", "prepared transaction does not reconstruct the intended settlement", err);
|
|
10048
10338
|
}
|
|
10049
10339
|
return prepared;
|
|
@@ -10615,10 +10905,10 @@ async function verifyGrantOnChain(input) {
|
|
|
10615
10905
|
ok: false,
|
|
10616
10906
|
error: manifestError(MANIFEST_ERROR_CODES.GRANT_NOT_VERIFIED, detail)
|
|
10617
10907
|
});
|
|
10618
|
-
if (!state.delegateAddress ||
|
|
10908
|
+
if (!state.delegateAddress || normalizeSuiAddress12(state.delegateAddress) !== normalizeSuiAddress12(input.delegateAddress)) {
|
|
10619
10909
|
return notVerified(`grant ${input.grantObjectId} does not name this delegate on chain`);
|
|
10620
10910
|
}
|
|
10621
|
-
if (!state.poolObjectId ||
|
|
10911
|
+
if (!state.poolObjectId || normalizeSuiAddress12(state.poolObjectId) !== normalizeSuiAddress12(input.poolObjectId)) {
|
|
10622
10912
|
return notVerified(`grant ${input.grantObjectId} draws on a different pool than the one resolved`);
|
|
10623
10913
|
}
|
|
10624
10914
|
if (state.revoked === true) {
|
|
@@ -10766,7 +11056,9 @@ async function createPayer(options) {
|
|
|
10766
11056
|
offer,
|
|
10767
11057
|
delegateAddress: address,
|
|
10768
11058
|
expectedGrantObjectId: binding.grantObjectId,
|
|
10769
|
-
expectedPoolObjectId: binding.poolObjectId
|
|
11059
|
+
expectedPoolObjectId: binding.poolObjectId,
|
|
11060
|
+
getCurrentEpoch: deps.getCurrentEpoch,
|
|
11061
|
+
getChainIdentifier: deps.getChainIdentifier
|
|
10770
11062
|
});
|
|
10771
11063
|
}
|
|
10772
11064
|
return {
|
|
@@ -10776,7 +11068,7 @@ async function createPayer(options) {
|
|
|
10776
11068
|
}
|
|
10777
11069
|
|
|
10778
11070
|
// ../sdk/dist/oauth/delegate-proof.js
|
|
10779
|
-
import { normalizeSuiAddress as
|
|
11071
|
+
import { normalizeSuiAddress as normalizeSuiAddress13 } from "@mysten/sui/utils";
|
|
10780
11072
|
import { verifyPersonalMessageSignature as verifyPersonalMessageSignature3 } from "@mysten/sui/verify";
|
|
10781
11073
|
var OAUTH_DELEGATE_PROOF_TTL_MS = 15 * 6e4;
|
|
10782
11074
|
function encodeOAuthDelegateProof(binding, expiresAtMs, ownerAddress) {
|
|
@@ -10790,8 +11082,8 @@ function encodeOAuthDelegateProof(binding, expiresAtMs, ownerAddress) {
|
|
|
10790
11082
|
binding.resource,
|
|
10791
11083
|
binding.scope,
|
|
10792
11084
|
binding.codeChallenge,
|
|
10793
|
-
|
|
10794
|
-
|
|
11085
|
+
normalizeSuiAddress13(binding.delegateAddress),
|
|
11086
|
+
normalizeSuiAddress13(ownerAddress),
|
|
10795
11087
|
expiresAtMs
|
|
10796
11088
|
]));
|
|
10797
11089
|
}
|
|
@@ -10801,10 +11093,10 @@ async function verifyOAuthDelegateProof(binding, proof, nowMs = Date.now(), expe
|
|
|
10801
11093
|
const message = encodeOAuthDelegateProof(binding, p.expiresAtMs, p.ownerAddress);
|
|
10802
11094
|
if (typeof p.signature !== "string" || p.signature.length > 8192 || p.expiresAtMs <= nowMs || p.expiresAtMs > nowMs + OAUTH_DELEGATE_PROOF_TTL_MS)
|
|
10803
11095
|
return false;
|
|
10804
|
-
if (expectedOwner &&
|
|
11096
|
+
if (expectedOwner && normalizeSuiAddress13(p.ownerAddress) !== normalizeSuiAddress13(expectedOwner))
|
|
10805
11097
|
return false;
|
|
10806
11098
|
const publicKey = await verifyPersonalMessageSignature3(message, p.signature);
|
|
10807
|
-
return publicKey.toSuiAddress() ===
|
|
11099
|
+
return publicKey.toSuiAddress() === normalizeSuiAddress13(binding.delegateAddress);
|
|
10808
11100
|
} catch {
|
|
10809
11101
|
return false;
|
|
10810
11102
|
}
|
package/package.json
CHANGED