@mysten-incubation/suipay-buyer 0.3.0 → 0.4.0-dev.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 +29 -0
- package/dist/{chunk-XSL5G2RU.js → chunk-BCI3TKYX.js} +352 -3
- package/dist/index.d.ts +107 -4
- package/dist/index.js +1042 -157
- package/dist/{native-transfer-GD3KlVqG.d.ts → native-transfer-DspFvMQc.d.ts} +102 -2
- package/dist/native-transfer.d.ts +1 -1
- package/dist/native-transfer.js +1 -1
- package/package.json +8 -3
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
parseErrorPayload,
|
|
14
14
|
stricterPaymentState,
|
|
15
15
|
toErrorFields
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-BCI3TKYX.js";
|
|
17
17
|
|
|
18
18
|
// src/mcp.ts
|
|
19
19
|
async function buildMcpPaymentPayload(paymentRequired, signer) {
|
|
@@ -339,7 +339,7 @@ function readIntent(body) {
|
|
|
339
339
|
// ../sdk/dist/buyer/verify-owner-transaction.js
|
|
340
340
|
import { TransactionDataBuilder } from "@mysten/sui/transactions";
|
|
341
341
|
import { bcs } from "@mysten/sui/bcs";
|
|
342
|
-
import { fromBase64, normalizeStructTag as
|
|
342
|
+
import { fromBase64, normalizeStructTag as normalizeStructTag4, normalizeSuiAddress } from "@mysten/sui/utils";
|
|
343
343
|
|
|
344
344
|
// ../core/dist/assets/testnet.js
|
|
345
345
|
import { normalizeStructTag } from "@mysten/sui/utils";
|
|
@@ -384,6 +384,68 @@ function tryNormalizeStructTag(coinType) {
|
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
386
|
|
|
387
|
+
// ../core/dist/assets/localnet.js
|
|
388
|
+
import { normalizeStructTag as normalizeStructTag2 } from "@mysten/sui/utils";
|
|
389
|
+
var LOCALNET_SUI_COIN_TYPE = TESTNET_SUI_COIN_TYPE;
|
|
390
|
+
var LOCALNET_SUI_DECIMALS = TESTNET_SUI_DECIMALS;
|
|
391
|
+
var LOCALNET_USDC_DECIMALS = 6;
|
|
392
|
+
function localnetAssets(usdcCoinType) {
|
|
393
|
+
const assets = [
|
|
394
|
+
{
|
|
395
|
+
id: "sui",
|
|
396
|
+
symbol: "SUI",
|
|
397
|
+
coinType: LOCALNET_SUI_COIN_TYPE,
|
|
398
|
+
decimals: LOCALNET_SUI_DECIMALS,
|
|
399
|
+
network: "sui:localnet"
|
|
400
|
+
}
|
|
401
|
+
];
|
|
402
|
+
const usdc = usdcCoinType?.trim();
|
|
403
|
+
if (usdc) {
|
|
404
|
+
try {
|
|
405
|
+
normalizeStructTag2(usdc);
|
|
406
|
+
} catch {
|
|
407
|
+
throw new Error(`localnet USDC coin type is not a valid coin type: ${usdc} (check SUIPAY_COIN_TYPE)`);
|
|
408
|
+
}
|
|
409
|
+
assets.push({
|
|
410
|
+
id: "usdc",
|
|
411
|
+
symbol: "USDC",
|
|
412
|
+
coinType: usdc,
|
|
413
|
+
decimals: LOCALNET_USDC_DECIMALS,
|
|
414
|
+
network: "sui:localnet"
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
return assets;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// ../core/dist/assets/index.js
|
|
421
|
+
import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui/utils";
|
|
422
|
+
function normalizeNetwork(network) {
|
|
423
|
+
const n = (network ?? "").trim();
|
|
424
|
+
return n === "sui:localnet" || n === "localnet" ? "sui:localnet" : "sui:testnet";
|
|
425
|
+
}
|
|
426
|
+
function assetsForNetwork(network, options) {
|
|
427
|
+
return normalizeNetwork(network) === "sui:localnet" ? localnetAssets(options?.usdcCoinType) : TESTNET_ASSETS;
|
|
428
|
+
}
|
|
429
|
+
function supportedAssetByCoinTypeForNetwork(coinType, network, options) {
|
|
430
|
+
if (normalizeNetwork(network) === "sui:testnet") {
|
|
431
|
+
return supportedAssetByCoinType(coinType);
|
|
432
|
+
}
|
|
433
|
+
const trimmed = coinType.trim();
|
|
434
|
+
if (!trimmed)
|
|
435
|
+
return null;
|
|
436
|
+
let target;
|
|
437
|
+
try {
|
|
438
|
+
target = normalizeStructTag3(trimmed);
|
|
439
|
+
} catch {
|
|
440
|
+
return null;
|
|
441
|
+
}
|
|
442
|
+
for (const asset of localnetAssets(options?.usdcCoinType)) {
|
|
443
|
+
if (normalizeStructTag3(asset.coinType) === target)
|
|
444
|
+
return asset;
|
|
445
|
+
}
|
|
446
|
+
return null;
|
|
447
|
+
}
|
|
448
|
+
|
|
387
449
|
// ../sdk/dist/sponsor/kind-gas-coin.js
|
|
388
450
|
function kindTouchesGasCoin(commands) {
|
|
389
451
|
return commands.some(namesGasCoin);
|
|
@@ -422,7 +484,7 @@ function safeNormalizeAddress(address) {
|
|
|
422
484
|
}
|
|
423
485
|
function safeNormalizeStructTag(tag) {
|
|
424
486
|
try {
|
|
425
|
-
return
|
|
487
|
+
return normalizeStructTag4(tag);
|
|
426
488
|
} catch {
|
|
427
489
|
}
|
|
428
490
|
return null;
|
|
@@ -514,13 +576,16 @@ function verifyOwnerTransaction(input) {
|
|
|
514
576
|
if (k === "TransferObjects" || k === "Publish" || k === "Upgrade") {
|
|
515
577
|
throw new TransactionVerificationError("unsupportedOperation");
|
|
516
578
|
}
|
|
517
|
-
if (k === "MakeMoveVec" && input.operation.kind !== "create_policy" && input.operation.kind !== "replace_grant") {
|
|
579
|
+
if (k === "MakeMoveVec" && input.operation.kind !== "create_policy" && input.operation.kind !== "replace_grant" && input.operation.kind !== "create_grant_consent_batch") {
|
|
518
580
|
throw new TransactionVerificationError("unsupportedOperation");
|
|
519
581
|
}
|
|
520
582
|
}
|
|
583
|
+
const networkAssets = assetsForNetwork(input.assetNetwork, {
|
|
584
|
+
usdcCoinType: input.localnetUsdcCoinType
|
|
585
|
+
});
|
|
521
586
|
const knownCoinPackages = /* @__PURE__ */ new Set([
|
|
522
587
|
FRAMEWORK_PACKAGE_ID,
|
|
523
|
-
...
|
|
588
|
+
...networkAssets.map((a) => safeNormalizeAddress(a.coinType.split("::")[0]))
|
|
524
589
|
]);
|
|
525
590
|
for (const cmd of commands) {
|
|
526
591
|
if (cmd.$kind === "MoveCall") {
|
|
@@ -673,7 +738,9 @@ function verifyOwnerTransaction(input) {
|
|
|
673
738
|
switch (op.kind) {
|
|
674
739
|
case "create_pool":
|
|
675
740
|
case "top_up": {
|
|
676
|
-
if (!
|
|
741
|
+
if (!supportedAssetByCoinTypeForNetwork(normCoinType, input.assetNetwork, {
|
|
742
|
+
usdcCoinType: input.localnetUsdcCoinType
|
|
743
|
+
})) {
|
|
677
744
|
throw new TransactionVerificationError("coinType");
|
|
678
745
|
}
|
|
679
746
|
let expectedAmt;
|
|
@@ -958,87 +1025,253 @@ function verifyOwnerTransaction(input) {
|
|
|
958
1025
|
allowedAssets.add(assetNorm);
|
|
959
1026
|
const existing = assetGroups.get(assetNorm) ?? {
|
|
960
1027
|
sumTotalCap: 0n,
|
|
961
|
-
policyIds: []
|
|
1028
|
+
policyIds: [],
|
|
1029
|
+
policies: []
|
|
962
1030
|
};
|
|
963
1031
|
existing.sumTotalCap += capAmt;
|
|
964
1032
|
existing.policyIds.push(p.id);
|
|
1033
|
+
existing.policies.push(p);
|
|
965
1034
|
assetGroups.set(assetNorm, existing);
|
|
966
1035
|
}
|
|
967
|
-
const
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
const seenCoins = /* @__PURE__ */ new Set();
|
|
973
|
-
const seenPools = /* @__PURE__ */ new Set();
|
|
974
|
-
for (let i = 0; i < batchN; i++) {
|
|
975
|
-
const cmd = commands[i];
|
|
976
|
-
if (cmd.$kind !== "MoveCall") {
|
|
977
|
-
throw new TransactionVerificationError("unsupportedOperation");
|
|
978
|
-
}
|
|
979
|
-
const mc = cmd.MoveCall;
|
|
980
|
-
if (mc.module !== "spend_account" || mc.function !== "create_policy_grant") {
|
|
981
|
-
throw new TransactionVerificationError("target");
|
|
982
|
-
}
|
|
983
|
-
const mcTypes = mc.typeArguments;
|
|
984
|
-
if (mcTypes.length !== 1) {
|
|
985
|
-
throw new TransactionVerificationError("coinType");
|
|
986
|
-
}
|
|
987
|
-
const cmdCoinType = safeNormalizeStructTag(mcTypes[0]);
|
|
988
|
-
if (!cmdCoinType || !allowedAssets.has(cmdCoinType)) {
|
|
989
|
-
throw new TransactionVerificationError("coinType");
|
|
990
|
-
}
|
|
991
|
-
if (seenCoins.has(cmdCoinType)) {
|
|
992
|
-
throw new TransactionVerificationError("coinType");
|
|
993
|
-
}
|
|
994
|
-
seenCoins.add(cmdCoinType);
|
|
995
|
-
const groupInfo = assetGroups.get(cmdCoinType);
|
|
996
|
-
const args = mc.arguments;
|
|
997
|
-
if (args.length !== 6) {
|
|
998
|
-
throw new TransactionVerificationError("target");
|
|
999
|
-
}
|
|
1000
|
-
const poolInputIdx = markInput(args[0]);
|
|
1001
|
-
const poolId = getObjectIdFromInput(data.inputs[poolInputIdx]);
|
|
1002
|
-
if (!poolId) {
|
|
1003
|
-
throw new TransactionVerificationError("pool");
|
|
1004
|
-
}
|
|
1005
|
-
if (seenPools.has(poolId)) {
|
|
1006
|
-
throw new TransactionVerificationError("pool");
|
|
1007
|
-
}
|
|
1008
|
-
seenPools.add(poolId);
|
|
1009
|
-
const delInputIdx = markInput(args[1]);
|
|
1010
|
-
const delBytes = getPureBytes(data.inputs[delInputIdx]);
|
|
1011
|
-
if (!delBytes || parseAddress(delBytes) !== safeNormalizeAddress(op.delegate.address)) {
|
|
1012
|
-
throw new TransactionVerificationError("delegate");
|
|
1013
|
-
}
|
|
1014
|
-
const capInputIdx = markInput(args[2]);
|
|
1015
|
-
const capBytes = getPureBytes(data.inputs[capInputIdx]);
|
|
1016
|
-
if (!capBytes) {
|
|
1017
|
-
throw new TransactionVerificationError("caps");
|
|
1036
|
+
const isCombined = commands.length >= 5 && commands[0]?.$kind === "MoveCall" && commands[0].MoveCall?.module === "spend_account" && commands[0].MoveCall?.function === "new_policy_target";
|
|
1037
|
+
if (!isCombined) {
|
|
1038
|
+
const hasDraftPolicy = uniquePolicies.some((p) => p.status === "draft" || p.onChainPolicyId == null && p.targets && p.targets.length > 0);
|
|
1039
|
+
if (hasDraftPolicy) {
|
|
1040
|
+
throw new TransactionVerificationError("policyId");
|
|
1018
1041
|
}
|
|
1019
|
-
const
|
|
1020
|
-
const
|
|
1021
|
-
|
|
1022
|
-
if (!maxBytes) {
|
|
1042
|
+
const distinctAssetCount = assetGroups.size;
|
|
1043
|
+
const batchN = commands.length;
|
|
1044
|
+
if (batchN > distinctAssetCount) {
|
|
1023
1045
|
throw new TransactionVerificationError("caps");
|
|
1024
1046
|
}
|
|
1025
|
-
const
|
|
1026
|
-
|
|
1027
|
-
|
|
1047
|
+
const seenCoins = /* @__PURE__ */ new Set();
|
|
1048
|
+
const seenPools = /* @__PURE__ */ new Set();
|
|
1049
|
+
for (let i = 0; i < batchN; i++) {
|
|
1050
|
+
const cmd = commands[i];
|
|
1051
|
+
if (cmd.$kind !== "MoveCall") {
|
|
1052
|
+
throw new TransactionVerificationError("unsupportedOperation");
|
|
1053
|
+
}
|
|
1054
|
+
const mc = cmd.MoveCall;
|
|
1055
|
+
if (mc.module !== "spend_account" || mc.function !== "create_policy_grant") {
|
|
1056
|
+
throw new TransactionVerificationError("target");
|
|
1057
|
+
}
|
|
1058
|
+
const mcTypes = mc.typeArguments;
|
|
1059
|
+
if (mcTypes.length !== 1) {
|
|
1060
|
+
throw new TransactionVerificationError("coinType");
|
|
1061
|
+
}
|
|
1062
|
+
const cmdCoinType2 = safeNormalizeStructTag(mcTypes[0]);
|
|
1063
|
+
if (!cmdCoinType2 || !allowedAssets.has(cmdCoinType2)) {
|
|
1064
|
+
throw new TransactionVerificationError("coinType");
|
|
1065
|
+
}
|
|
1066
|
+
if (seenCoins.has(cmdCoinType2)) {
|
|
1067
|
+
throw new TransactionVerificationError("coinType");
|
|
1068
|
+
}
|
|
1069
|
+
seenCoins.add(cmdCoinType2);
|
|
1070
|
+
const groupInfo2 = assetGroups.get(cmdCoinType2);
|
|
1071
|
+
const args = mc.arguments;
|
|
1072
|
+
if (args.length !== 6) {
|
|
1073
|
+
throw new TransactionVerificationError("target");
|
|
1074
|
+
}
|
|
1075
|
+
const poolInputIdx2 = markInput(args[0]);
|
|
1076
|
+
const poolId2 = getObjectIdFromInput(data.inputs[poolInputIdx2]);
|
|
1077
|
+
if (!poolId2) {
|
|
1078
|
+
throw new TransactionVerificationError("pool");
|
|
1079
|
+
}
|
|
1080
|
+
if (seenPools.has(poolId2)) {
|
|
1081
|
+
throw new TransactionVerificationError("pool");
|
|
1082
|
+
}
|
|
1083
|
+
seenPools.add(poolId2);
|
|
1084
|
+
const delInputIdx2 = markInput(args[1]);
|
|
1085
|
+
const delBytes2 = getPureBytes(data.inputs[delInputIdx2]);
|
|
1086
|
+
if (!delBytes2 || parseAddress(delBytes2) !== safeNormalizeAddress(op.delegate.address)) {
|
|
1087
|
+
throw new TransactionVerificationError("delegate");
|
|
1088
|
+
}
|
|
1089
|
+
const capInputIdx2 = markInput(args[2]);
|
|
1090
|
+
const capBytes2 = getPureBytes(data.inputs[capInputIdx2]);
|
|
1091
|
+
if (!capBytes2) {
|
|
1092
|
+
throw new TransactionVerificationError("caps");
|
|
1093
|
+
}
|
|
1094
|
+
const txSessionCap2 = parseOptionU64(capBytes2);
|
|
1095
|
+
const maxInputIdx2 = markInput(args[3]);
|
|
1096
|
+
const maxBytes2 = getPureBytes(data.inputs[maxInputIdx2]);
|
|
1097
|
+
if (!maxBytes2) {
|
|
1098
|
+
throw new TransactionVerificationError("caps");
|
|
1099
|
+
}
|
|
1100
|
+
const txMaxPerPayment2 = parseOptionU64(maxBytes2);
|
|
1101
|
+
if (txSessionCap2 === null || txMaxPerPayment2 !== txSessionCap2) {
|
|
1102
|
+
throw new TransactionVerificationError("caps");
|
|
1103
|
+
}
|
|
1104
|
+
if (txSessionCap2 > groupInfo2.sumTotalCap) {
|
|
1105
|
+
throw new TransactionVerificationError("caps");
|
|
1106
|
+
}
|
|
1107
|
+
assertPureU64(args[4], 0n, "expiry");
|
|
1108
|
+
const pIdsInputIdx = markInput(args[5]);
|
|
1109
|
+
const pIdsBytes = getPureBytes(data.inputs[pIdsInputIdx]);
|
|
1110
|
+
if (!pIdsBytes) {
|
|
1111
|
+
throw new TransactionVerificationError("policyId");
|
|
1112
|
+
}
|
|
1113
|
+
const parsedPids = bcs.vector(bcs.u64()).parse(pIdsBytes);
|
|
1114
|
+
const expectedOnChainIds = groupInfo2.policies.map((p) => p.onChainPolicyId != null ? String(p.onChainPolicyId) : null).filter((id) => id != null);
|
|
1115
|
+
if (expectedOnChainIds.length === 0 || expectedOnChainIds.length !== groupInfo2.policies.length || parsedPids.length !== expectedOnChainIds.length) {
|
|
1116
|
+
throw new TransactionVerificationError("policyId");
|
|
1117
|
+
}
|
|
1118
|
+
for (let idx = 0; idx < parsedPids.length; idx++) {
|
|
1119
|
+
if (String(parsedPids[idx]) !== expectedOnChainIds[idx]) {
|
|
1120
|
+
throw new TransactionVerificationError("policyId");
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1028
1123
|
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1124
|
+
break;
|
|
1125
|
+
}
|
|
1126
|
+
if (uniquePolicies.length !== 1) {
|
|
1127
|
+
throw new TransactionVerificationError("targets");
|
|
1128
|
+
}
|
|
1129
|
+
const draftPolicy = uniquePolicies[0];
|
|
1130
|
+
let N = 0;
|
|
1131
|
+
while (N < commands.length && commands[N]?.$kind === "MoveCall" && commands[N].MoveCall?.module === "spend_account" && commands[N].MoveCall?.function === "new_policy_target") {
|
|
1132
|
+
N++;
|
|
1133
|
+
}
|
|
1134
|
+
if (!draftPolicy.targets || draftPolicy.targets.length !== N) {
|
|
1135
|
+
throw new TransactionVerificationError("targets");
|
|
1136
|
+
}
|
|
1137
|
+
if (commands.length !== N + 4) {
|
|
1138
|
+
throw new TransactionVerificationError("targets");
|
|
1139
|
+
}
|
|
1140
|
+
for (let i = 0; i < N; i++) {
|
|
1141
|
+
const c = commands[i];
|
|
1142
|
+
const mc = c.MoveCall;
|
|
1143
|
+
if (mc.arguments.length !== 3) {
|
|
1144
|
+
throw new TransactionVerificationError("target");
|
|
1031
1145
|
}
|
|
1032
|
-
|
|
1033
|
-
const
|
|
1034
|
-
const
|
|
1035
|
-
|
|
1036
|
-
|
|
1146
|
+
const expectedTarget = draftPolicy.targets[i];
|
|
1147
|
+
const hashIdx = markInput(mc.arguments[0]);
|
|
1148
|
+
const hashBytes = getPureBytes(data.inputs[hashIdx]);
|
|
1149
|
+
const hash = hashBytes ? bcs.vector(bcs.u8()).parse(hashBytes) : null;
|
|
1150
|
+
const got = hash ? [...hash].map((byte) => byte.toString(16).padStart(2, "0")).join("") : "";
|
|
1151
|
+
const want = expectedTarget.targetHash.trim().toLowerCase().replace(/^0x/, "");
|
|
1152
|
+
if (!hash || got !== want)
|
|
1153
|
+
throw new TransactionVerificationError("target");
|
|
1154
|
+
const recipientIdx = markInput(mc.arguments[1]);
|
|
1155
|
+
const recipientBytes = getPureBytes(data.inputs[recipientIdx]);
|
|
1156
|
+
if (!recipientBytes || parseAddress(recipientBytes) !== safeNormalizeAddress(expectedTarget.recipient)) {
|
|
1157
|
+
throw new TransactionVerificationError("target");
|
|
1037
1158
|
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1159
|
+
assertPureU64(mc.arguments[2], BigInt(expectedTarget.maxPerPayment), "target");
|
|
1160
|
+
}
|
|
1161
|
+
const vecCmd = commands[N];
|
|
1162
|
+
if (vecCmd.$kind !== "MakeMoveVec") {
|
|
1163
|
+
throw new TransactionVerificationError("unsupportedOperation");
|
|
1164
|
+
}
|
|
1165
|
+
const targetElements = vecCmd.MakeMoveVec?.elements;
|
|
1166
|
+
if (!Array.isArray(targetElements) || targetElements.length !== N) {
|
|
1167
|
+
throw new TransactionVerificationError("targets");
|
|
1168
|
+
}
|
|
1169
|
+
for (let i = 0; i < N; i++) {
|
|
1170
|
+
const el = markResult(targetElements[i], "targets");
|
|
1171
|
+
if (el.cmdIndex !== i || el.resIndex !== 0) {
|
|
1172
|
+
throw new TransactionVerificationError("targets");
|
|
1040
1173
|
}
|
|
1041
1174
|
}
|
|
1175
|
+
const createPolicyCmd = commands[N + 1];
|
|
1176
|
+
if (createPolicyCmd.$kind !== "MoveCall" || createPolicyCmd.MoveCall?.module !== "spend_account" || createPolicyCmd.MoveCall?.function !== "create_spend_policy") {
|
|
1177
|
+
throw new TransactionVerificationError("target");
|
|
1178
|
+
}
|
|
1179
|
+
const policyTypes = createPolicyCmd.MoveCall.typeArguments;
|
|
1180
|
+
if (!policyTypes || policyTypes.length !== 1) {
|
|
1181
|
+
throw new TransactionVerificationError("coinType");
|
|
1182
|
+
}
|
|
1183
|
+
const cmdCoinType = safeNormalizeStructTag(policyTypes[0]);
|
|
1184
|
+
if (!cmdCoinType || !allowedAssets.has(cmdCoinType)) {
|
|
1185
|
+
throw new TransactionVerificationError("coinType");
|
|
1186
|
+
}
|
|
1187
|
+
const groupInfo = assetGroups.get(cmdCoinType);
|
|
1188
|
+
const policyArgs = createPolicyCmd.MoveCall.arguments;
|
|
1189
|
+
if (!policyArgs || policyArgs.length !== 5) {
|
|
1190
|
+
throw new TransactionVerificationError("target");
|
|
1191
|
+
}
|
|
1192
|
+
const poolInputIdx = markInput(policyArgs[0]);
|
|
1193
|
+
const poolId = getObjectIdFromInput(data.inputs[poolInputIdx]);
|
|
1194
|
+
if (!poolId) {
|
|
1195
|
+
throw new TransactionVerificationError("pool");
|
|
1196
|
+
}
|
|
1197
|
+
const targetsRes = markResult(policyArgs[1], "unsupportedOperation");
|
|
1198
|
+
if (targetsRes.cmdIndex !== N || targetsRes.resIndex !== 0) {
|
|
1199
|
+
throw new TransactionVerificationError("unsupportedOperation");
|
|
1200
|
+
}
|
|
1201
|
+
const totalCapInputIdx = markInput(policyArgs[2]);
|
|
1202
|
+
const totalCapBytes = getPureBytes(data.inputs[totalCapInputIdx]);
|
|
1203
|
+
if (!totalCapBytes)
|
|
1204
|
+
throw new TransactionVerificationError("caps");
|
|
1205
|
+
const policyTotalCap = parseU64(totalCapBytes);
|
|
1206
|
+
if (policyTotalCap <= 0n || policyTotalCap > groupInfo.sumTotalCap || policyTotalCap !== BigInt(draftPolicy.totalCap)) {
|
|
1207
|
+
throw new TransactionVerificationError("caps");
|
|
1208
|
+
}
|
|
1209
|
+
const maxPerPaymentInputIdx = markInput(policyArgs[3]);
|
|
1210
|
+
const maxPerPaymentBytes = getPureBytes(data.inputs[maxPerPaymentInputIdx]);
|
|
1211
|
+
if (!maxPerPaymentBytes)
|
|
1212
|
+
throw new TransactionVerificationError("caps");
|
|
1213
|
+
const policyMaxPerPayment = parseU64(maxPerPaymentBytes);
|
|
1214
|
+
if (policyMaxPerPayment <= 0n || policyMaxPerPayment > policyTotalCap || draftPolicy.maxPerPayment == null || policyMaxPerPayment !== BigInt(draftPolicy.maxPerPayment)) {
|
|
1215
|
+
throw new TransactionVerificationError("caps");
|
|
1216
|
+
}
|
|
1217
|
+
assertPureU64(policyArgs[4], callerExpiryU64(draftPolicy.expiresAtMs), "expiry");
|
|
1218
|
+
const idVecCmd = commands[N + 2];
|
|
1219
|
+
if (idVecCmd.$kind !== "MakeMoveVec" || !Array.isArray(idVecCmd.MakeMoveVec?.elements) || idVecCmd.MakeMoveVec.elements.length !== 1) {
|
|
1220
|
+
throw new TransactionVerificationError("policyId");
|
|
1221
|
+
}
|
|
1222
|
+
const policyRes = markResult(idVecCmd.MakeMoveVec.elements[0], "policyId");
|
|
1223
|
+
if (policyRes.cmdIndex !== N + 1 || policyRes.resIndex !== 0) {
|
|
1224
|
+
throw new TransactionVerificationError("policyId");
|
|
1225
|
+
}
|
|
1226
|
+
const grantCmd = commands[N + 3];
|
|
1227
|
+
if (grantCmd.$kind !== "MoveCall" || grantCmd.MoveCall?.module !== "spend_account" || grantCmd.MoveCall?.function !== "create_policy_grant") {
|
|
1228
|
+
throw new TransactionVerificationError("target");
|
|
1229
|
+
}
|
|
1230
|
+
const grantTypes = grantCmd.MoveCall.typeArguments;
|
|
1231
|
+
if (!grantTypes || grantTypes.length !== 1) {
|
|
1232
|
+
throw new TransactionVerificationError("coinType");
|
|
1233
|
+
}
|
|
1234
|
+
const grantCoinType = safeNormalizeStructTag(grantTypes[0]);
|
|
1235
|
+
if (grantCoinType !== cmdCoinType) {
|
|
1236
|
+
throw new TransactionVerificationError("coinType");
|
|
1237
|
+
}
|
|
1238
|
+
const grantArgs = grantCmd.MoveCall.arguments;
|
|
1239
|
+
if (!grantArgs || grantArgs.length !== 6) {
|
|
1240
|
+
throw new TransactionVerificationError("target");
|
|
1241
|
+
}
|
|
1242
|
+
const grantPoolInputIdx = markInput(grantArgs[0]);
|
|
1243
|
+
const grantPoolId = getObjectIdFromInput(data.inputs[grantPoolInputIdx]);
|
|
1244
|
+
if (!grantPoolId || grantPoolId !== poolId) {
|
|
1245
|
+
throw new TransactionVerificationError("pool");
|
|
1246
|
+
}
|
|
1247
|
+
const delInputIdx = markInput(grantArgs[1]);
|
|
1248
|
+
const delBytes = getPureBytes(data.inputs[delInputIdx]);
|
|
1249
|
+
if (!delBytes || parseAddress(delBytes) !== safeNormalizeAddress(op.delegate.address)) {
|
|
1250
|
+
throw new TransactionVerificationError("delegate");
|
|
1251
|
+
}
|
|
1252
|
+
const capInputIdx = markInput(grantArgs[2]);
|
|
1253
|
+
const capBytes = getPureBytes(data.inputs[capInputIdx]);
|
|
1254
|
+
if (!capBytes) {
|
|
1255
|
+
throw new TransactionVerificationError("caps");
|
|
1256
|
+
}
|
|
1257
|
+
const txSessionCap = parseOptionU64(capBytes);
|
|
1258
|
+
const maxInputIdx = markInput(grantArgs[3]);
|
|
1259
|
+
const maxBytes = getPureBytes(data.inputs[maxInputIdx]);
|
|
1260
|
+
if (!maxBytes) {
|
|
1261
|
+
throw new TransactionVerificationError("caps");
|
|
1262
|
+
}
|
|
1263
|
+
const txMaxPerPayment = parseOptionU64(maxBytes);
|
|
1264
|
+
if (txSessionCap === null || txMaxPerPayment !== txSessionCap) {
|
|
1265
|
+
throw new TransactionVerificationError("caps");
|
|
1266
|
+
}
|
|
1267
|
+
if (txSessionCap > groupInfo.sumTotalCap) {
|
|
1268
|
+
throw new TransactionVerificationError("caps");
|
|
1269
|
+
}
|
|
1270
|
+
assertPureU64(grantArgs[4], 0n, "expiry");
|
|
1271
|
+
const grantVecRes = markResult(grantArgs[5], "policyId");
|
|
1272
|
+
if (grantVecRes.cmdIndex !== N + 2 || grantVecRes.resIndex !== 0) {
|
|
1273
|
+
throw new TransactionVerificationError("policyId");
|
|
1274
|
+
}
|
|
1042
1275
|
break;
|
|
1043
1276
|
}
|
|
1044
1277
|
case "create_grant_open": {
|
|
@@ -1481,6 +1714,25 @@ async function executeSignedDigest(transport, input) {
|
|
|
1481
1714
|
return ok({ digest: confirmed });
|
|
1482
1715
|
}
|
|
1483
1716
|
|
|
1717
|
+
// ../sdk/dist/buyer/owner-anchors.js
|
|
1718
|
+
var SCOPED_GRANT_FN = "create_policy_grant";
|
|
1719
|
+
var OPEN_GRANT_FN = "create_open_recipient_grant";
|
|
1720
|
+
function declaredAsset(asset, assets = TESTNET_ASSETS) {
|
|
1721
|
+
if (typeof asset !== "string")
|
|
1722
|
+
return null;
|
|
1723
|
+
const trimmed = asset.trim();
|
|
1724
|
+
const byLabel = assets.find((a) => a.id === trimmed.toLowerCase());
|
|
1725
|
+
if (byLabel)
|
|
1726
|
+
return byLabel;
|
|
1727
|
+
const byCoin = supportedAssetByCoinType(trimmed);
|
|
1728
|
+
return byCoin && assets.some((a) => a.id === byCoin.id) ? byCoin : null;
|
|
1729
|
+
}
|
|
1730
|
+
function assertMoveFunction(target, expected) {
|
|
1731
|
+
const fn = typeof target === "string" ? target.split("::").at(-1) : void 0;
|
|
1732
|
+
if (fn !== expected)
|
|
1733
|
+
throw new TransactionVerificationError("target");
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1484
1736
|
// ../sdk/dist/buyer/v1/delegated-signers.js
|
|
1485
1737
|
function createAgentsApi(transport) {
|
|
1486
1738
|
async function list() {
|
|
@@ -1580,26 +1832,46 @@ function createAgentsApi(transport) {
|
|
|
1580
1832
|
if (!created.ok)
|
|
1581
1833
|
return created;
|
|
1582
1834
|
const finalized = [];
|
|
1835
|
+
for (const submitted of created.value.submitted ?? []) {
|
|
1836
|
+
const fin = await finalizeGrant(created.value.delegatedSignerId, submitted.grantId, submitted.digest);
|
|
1837
|
+
if (!fin.ok)
|
|
1838
|
+
return fin;
|
|
1839
|
+
finalized.push(fin.value);
|
|
1840
|
+
}
|
|
1583
1841
|
for (const grant of created.value.grants) {
|
|
1584
|
-
const
|
|
1585
|
-
|
|
1586
|
-
const
|
|
1587
|
-
const
|
|
1588
|
-
|
|
1589
|
-
coinType
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1842
|
+
const open = input.accessMode === "open";
|
|
1843
|
+
assertMoveFunction(grant.moveTarget, open ? OPEN_GRANT_FN : SCOPED_GRANT_FN);
|
|
1844
|
+
const grantAsset = declaredAsset(grant.coinType) ?? declaredAsset(grant.asset);
|
|
1845
|
+
const scope = grantAsset ? input.assetScopes.find((s) => declaredAsset(s.asset)?.id === grantAsset.id) : void 0;
|
|
1846
|
+
if (!grantAsset || !scope)
|
|
1847
|
+
throw new TransactionVerificationError("coinType");
|
|
1848
|
+
const coinType = grantAsset.coinType;
|
|
1849
|
+
const delegate = { address: input.agentAddress, source: "independent" };
|
|
1850
|
+
const expiresAtMs = scope.expiresAt != null ? String(scope.expiresAt) : "0";
|
|
1851
|
+
let operation;
|
|
1852
|
+
if (open) {
|
|
1853
|
+
if (scope.totalBudgetAtomic == null || scope.maxPerPaymentAtomic == null) {
|
|
1854
|
+
throw new TransactionVerificationError("caps");
|
|
1855
|
+
}
|
|
1856
|
+
operation = {
|
|
1857
|
+
kind: "create_grant_open",
|
|
1858
|
+
coinType,
|
|
1859
|
+
delegate,
|
|
1860
|
+
sessionCap: BigInt(scope.totalBudgetAtomic),
|
|
1861
|
+
maxPerPayment: BigInt(scope.maxPerPaymentAtomic),
|
|
1862
|
+
expiresAtMs
|
|
1863
|
+
};
|
|
1864
|
+
} else {
|
|
1865
|
+
operation = {
|
|
1866
|
+
kind: "create_grant_scoped",
|
|
1867
|
+
coinType,
|
|
1868
|
+
delegate,
|
|
1869
|
+
sessionCap: scope.totalBudgetAtomic,
|
|
1870
|
+
maxPerPayment: scope.maxPerPaymentAtomic,
|
|
1871
|
+
expiresAtMs,
|
|
1872
|
+
...input.policyIds !== void 0 ? { policyIdCount: input.policyIds.length } : {}
|
|
1873
|
+
};
|
|
1874
|
+
}
|
|
1603
1875
|
const signed = await sponsorAndSignKind(transport, {
|
|
1604
1876
|
kindBytes: grant.txKindBytes,
|
|
1605
1877
|
sender: signerRes.value.address,
|
|
@@ -1817,41 +2089,97 @@ function createPoliciesApi(transport, intents) {
|
|
|
1817
2089
|
return fail(response);
|
|
1818
2090
|
return ok(parsed.intent);
|
|
1819
2091
|
}
|
|
1820
|
-
async function getPoolObjectId(
|
|
2092
|
+
async function getPoolObjectId(assetId, coinType) {
|
|
1821
2093
|
const response = await transport.request("/v1/buyer/pools");
|
|
1822
2094
|
if (response.status !== 200 || !isRecord(response.body) || !Array.isArray(response.body.pools)) {
|
|
1823
2095
|
return null;
|
|
1824
2096
|
}
|
|
1825
2097
|
const pools = asDto(response.body.pools);
|
|
1826
|
-
const found = pools.find((p) =>
|
|
2098
|
+
const found = pools.find((p) => declaredAsset(p.coinType)?.coinType === coinType || declaredAsset(p.asset)?.id === assetId);
|
|
1827
2099
|
return found?.objectId ?? null;
|
|
1828
2100
|
}
|
|
1829
|
-
|
|
2101
|
+
function readExpectation(options) {
|
|
2102
|
+
if (!isRecord(options) || !isRecord(options.expected))
|
|
2103
|
+
return null;
|
|
2104
|
+
const e = options.expected;
|
|
2105
|
+
const asset = declaredAsset(e.asset);
|
|
2106
|
+
if (!asset)
|
|
2107
|
+
return null;
|
|
2108
|
+
const positive = (v) => typeof v === "string" && /^[1-9][0-9]*$/.test(v);
|
|
2109
|
+
if (!positive(e.totalCap) || !positive(e.maxPerPayment))
|
|
2110
|
+
return null;
|
|
2111
|
+
if (!Number.isInteger(e.targetCount) || e.targetCount < 1)
|
|
2112
|
+
return null;
|
|
2113
|
+
const exp = e.expiresAt;
|
|
2114
|
+
if (exp != null && typeof exp !== "string" && typeof exp !== "number")
|
|
2115
|
+
return null;
|
|
2116
|
+
return {
|
|
2117
|
+
asset,
|
|
2118
|
+
terms: {
|
|
2119
|
+
asset: e.asset,
|
|
2120
|
+
totalCap: e.totalCap,
|
|
2121
|
+
maxPerPayment: e.maxPerPayment,
|
|
2122
|
+
expiresAt: exp,
|
|
2123
|
+
targetCount: e.targetCount
|
|
2124
|
+
}
|
|
2125
|
+
};
|
|
2126
|
+
}
|
|
2127
|
+
async function activate(id, options) {
|
|
2128
|
+
const read = readExpectation(options);
|
|
2129
|
+
if (!read) {
|
|
2130
|
+
return failLocal(400, "request.invalid", "not_charged", {
|
|
2131
|
+
message: "policies.activate needs options.expected: the asset, totalCap, maxPerPayment, expiresAt and targetCount the policy was created with"
|
|
2132
|
+
});
|
|
2133
|
+
}
|
|
2134
|
+
const { terms: expected, asset } = read;
|
|
1830
2135
|
const policyRes = await get(id);
|
|
1831
2136
|
if (!policyRes.ok)
|
|
1832
2137
|
return policyRes;
|
|
1833
2138
|
const policy = policyRes.value;
|
|
1834
|
-
const
|
|
2139
|
+
const rowAsset = declaredAsset(policy.asset) ?? declaredAsset(policy.coinType);
|
|
2140
|
+
if (rowAsset?.id !== asset.id) {
|
|
2141
|
+
return failLocal(400, "request.invalid", "not_charged", {
|
|
2142
|
+
message: `Policy ${id} is for ${policy.asset}, not the expected asset ${asset.id}`
|
|
2143
|
+
});
|
|
2144
|
+
}
|
|
2145
|
+
const poolObjectId = await getPoolObjectId(asset.id, asset.coinType);
|
|
1835
2146
|
if (!poolObjectId) {
|
|
1836
2147
|
return failLocal(400, "request.invalid", "not_charged", {
|
|
1837
|
-
message: `No active spend account pool found for asset ${
|
|
2148
|
+
message: `No active spend account pool found for asset ${asset.id}`
|
|
1838
2149
|
});
|
|
1839
2150
|
}
|
|
1840
|
-
const assetMatch = TESTNET_ASSETS.find((a) => a.id === policy.asset.toLowerCase() || a.symbol.toLowerCase() === policy.asset.toLowerCase() || a.coinType.toLowerCase() === policy.asset.toLowerCase()) ?? supportedAssetByCoinType(policy.coinType);
|
|
1841
|
-
const coinType = assetMatch?.coinType ?? policy.coinType;
|
|
1842
2151
|
const operation = {
|
|
1843
2152
|
kind: "create_policy",
|
|
1844
|
-
coinType,
|
|
2153
|
+
coinType: asset.coinType,
|
|
1845
2154
|
poolObjectId,
|
|
1846
|
-
totalCap:
|
|
1847
|
-
maxPerPayment:
|
|
1848
|
-
expiresAtMs:
|
|
1849
|
-
targetCount:
|
|
2155
|
+
totalCap: expected.totalCap,
|
|
2156
|
+
maxPerPayment: expected.maxPerPayment,
|
|
2157
|
+
expiresAtMs: expected.expiresAt ?? "0",
|
|
2158
|
+
targetCount: expected.targetCount
|
|
1850
2159
|
};
|
|
1851
2160
|
const prepared = await prepareAction(id, "/prepare");
|
|
1852
2161
|
if (!prepared.ok)
|
|
1853
2162
|
return prepared;
|
|
1854
|
-
return intents.execute(prepared.value, operation, signer);
|
|
2163
|
+
return intents.execute(prepared.value, operation, options.signer);
|
|
2164
|
+
}
|
|
2165
|
+
async function createAndActivate(input, signer) {
|
|
2166
|
+
const created = await create(input);
|
|
2167
|
+
if (!created.ok)
|
|
2168
|
+
return created;
|
|
2169
|
+
const serviceIds = new Set(input.serviceIds.map((s) => s.trim()).filter(Boolean));
|
|
2170
|
+
const activated = await activate(created.value.id, {
|
|
2171
|
+
expected: {
|
|
2172
|
+
asset: input.asset,
|
|
2173
|
+
totalCap: input.totalCap,
|
|
2174
|
+
maxPerPayment: input.maxPerPayment,
|
|
2175
|
+
expiresAt: input.expiresAt ?? null,
|
|
2176
|
+
targetCount: serviceIds.size
|
|
2177
|
+
},
|
|
2178
|
+
...signer ? { signer } : {}
|
|
2179
|
+
});
|
|
2180
|
+
if (!activated.ok)
|
|
2181
|
+
return activated;
|
|
2182
|
+
return ok({ ...activated.value, policy: created.value }, activated.status);
|
|
1855
2183
|
}
|
|
1856
2184
|
async function runLifecycle(id, action, suffix, signer) {
|
|
1857
2185
|
const policyRes = await get(id);
|
|
@@ -1863,18 +2191,22 @@ function createPoliciesApi(transport, intents) {
|
|
|
1863
2191
|
message: `Policy ${id} is not active on-chain (missing onChainPolicyId)`
|
|
1864
2192
|
});
|
|
1865
2193
|
}
|
|
1866
|
-
const
|
|
2194
|
+
const asset = declaredAsset(policy.asset) ?? declaredAsset(policy.coinType);
|
|
2195
|
+
if (!asset) {
|
|
2196
|
+
return failLocal(400, "request.invalid", "not_charged", {
|
|
2197
|
+
message: `Unsupported asset ${policy.asset} for policy ${id}`
|
|
2198
|
+
});
|
|
2199
|
+
}
|
|
2200
|
+
const poolObjectId = await getPoolObjectId(asset.id, asset.coinType);
|
|
1867
2201
|
if (!poolObjectId) {
|
|
1868
2202
|
return failLocal(400, "request.invalid", "not_charged", {
|
|
1869
|
-
message: `No active spend account pool found for asset ${
|
|
2203
|
+
message: `No active spend account pool found for asset ${asset.id}`
|
|
1870
2204
|
});
|
|
1871
2205
|
}
|
|
1872
|
-
const assetMatch = TESTNET_ASSETS.find((a) => a.id === policy.asset.toLowerCase() || a.symbol.toLowerCase() === policy.asset.toLowerCase() || a.coinType.toLowerCase() === policy.asset.toLowerCase()) ?? supportedAssetByCoinType(policy.coinType);
|
|
1873
|
-
const coinType = assetMatch?.coinType ?? policy.coinType;
|
|
1874
2206
|
const operation = {
|
|
1875
2207
|
kind: "policy_lifecycle",
|
|
1876
2208
|
action,
|
|
1877
|
-
coinType,
|
|
2209
|
+
coinType: asset.coinType,
|
|
1878
2210
|
poolObjectId,
|
|
1879
2211
|
onChainPolicyId: policy.onChainPolicyId
|
|
1880
2212
|
};
|
|
@@ -1892,6 +2224,7 @@ function createPoliciesApi(transport, intents) {
|
|
|
1892
2224
|
prepareResume: (id) => prepareAction(id, "/resume/prepare"),
|
|
1893
2225
|
prepareRevoke: (id) => prepareAction(id, "/revoke/prepare"),
|
|
1894
2226
|
activate,
|
|
2227
|
+
createAndActivate,
|
|
1895
2228
|
pause: (id, signer) => runLifecycle(id, "pause", "/pause/prepare", signer),
|
|
1896
2229
|
resume: (id, signer) => runLifecycle(id, "resume", "/resume/prepare", signer),
|
|
1897
2230
|
revoke: (id, signer) => runLifecycle(id, "revoke", "/revoke/prepare", signer)
|
|
@@ -2012,16 +2345,16 @@ function createSessionsApi(transport, intents) {
|
|
|
2012
2345
|
message: "No delegate address provided or found in connection listing"
|
|
2013
2346
|
});
|
|
2014
2347
|
}
|
|
2015
|
-
const
|
|
2016
|
-
if (!
|
|
2348
|
+
const declaredAsset2 = input.asset ?? conn?.asset;
|
|
2349
|
+
if (!declaredAsset2) {
|
|
2017
2350
|
return failLocal(400, "request.invalid", "not_charged", {
|
|
2018
2351
|
message: "No declared asset provided for grant"
|
|
2019
2352
|
});
|
|
2020
2353
|
}
|
|
2021
|
-
const assetMatch = TESTNET_ASSETS.find((a) => a.id ===
|
|
2354
|
+
const assetMatch = TESTNET_ASSETS.find((a) => a.id === declaredAsset2.toLowerCase() || a.symbol.toLowerCase() === declaredAsset2.toLowerCase() || a.coinType.toLowerCase() === declaredAsset2.toLowerCase());
|
|
2022
2355
|
if (!assetMatch) {
|
|
2023
2356
|
return failLocal(400, "request.invalid", "not_charged", {
|
|
2024
|
-
message: `Unsupported asset ${
|
|
2357
|
+
message: `Unsupported asset ${declaredAsset2} for grant`
|
|
2025
2358
|
});
|
|
2026
2359
|
}
|
|
2027
2360
|
const coinType = assetMatch.coinType;
|
|
@@ -2313,7 +2646,7 @@ function wrapFailover(clients, options = {}) {
|
|
|
2313
2646
|
|
|
2314
2647
|
// ../sdk/dist/buyer-control/chain.js
|
|
2315
2648
|
import { Transaction as Transaction2, coinWithBalance } from "@mysten/sui/transactions";
|
|
2316
|
-
import { fromBase64 as fromBase643, normalizeStructTag as
|
|
2649
|
+
import { fromBase64 as fromBase643, normalizeStructTag as normalizeStructTag6, normalizeSuiAddress as normalizeSuiAddress3, toBase64 } from "@mysten/sui/utils";
|
|
2317
2650
|
|
|
2318
2651
|
// ../core/dist/chain/address.js
|
|
2319
2652
|
function hexOf(address) {
|
|
@@ -2357,7 +2690,7 @@ function objectTypeFromGetObject(object) {
|
|
|
2357
2690
|
|
|
2358
2691
|
// ../core/dist/policy/target.js
|
|
2359
2692
|
import { createHash } from "crypto";
|
|
2360
|
-
import { normalizeStructTag as
|
|
2693
|
+
import { normalizeStructTag as normalizeStructTag5 } from "@mysten/sui/utils";
|
|
2361
2694
|
|
|
2362
2695
|
// ../core/dist/service-state/index.js
|
|
2363
2696
|
var STATE_DIMENSIONS = Object.freeze([
|
|
@@ -2574,6 +2907,14 @@ var SERVICE_STATE_TRANSITIONS = Object.freeze([
|
|
|
2574
2907
|
to: "payout_change",
|
|
2575
2908
|
actors: ["system"],
|
|
2576
2909
|
requires: ["reason_code"]
|
|
2910
|
+
},
|
|
2911
|
+
{
|
|
2912
|
+
id: "T25",
|
|
2913
|
+
dimension: "suspension",
|
|
2914
|
+
from: ["binding_changed"],
|
|
2915
|
+
to: "none",
|
|
2916
|
+
actors: ["system"],
|
|
2917
|
+
requires: ["reason_code"]
|
|
2577
2918
|
}
|
|
2578
2919
|
]);
|
|
2579
2920
|
|
|
@@ -2743,7 +3084,7 @@ var MODULE = "spend_account";
|
|
|
2743
3084
|
var SUI_COIN_TYPE = "0x2::sui::SUI";
|
|
2744
3085
|
function isSuiCoinType(coinType) {
|
|
2745
3086
|
try {
|
|
2746
|
-
return
|
|
3087
|
+
return normalizeStructTag6(coinType) === normalizeStructTag6(SUI_COIN_TYPE);
|
|
2747
3088
|
} catch {
|
|
2748
3089
|
return /::sui::SUI$/i.test(coinType);
|
|
2749
3090
|
}
|
|
@@ -2973,6 +3314,70 @@ function createSpendAccountChain(options) {
|
|
|
2973
3314
|
});
|
|
2974
3315
|
return kindBytes(tx);
|
|
2975
3316
|
},
|
|
3317
|
+
async buildCreatePolicyAndGrantKind(input) {
|
|
3318
|
+
if (!input.policy.targets?.length) {
|
|
3319
|
+
throw new Error("create_spend_policy requires at least one target");
|
|
3320
|
+
}
|
|
3321
|
+
if (!input.policy.totalCap || BigInt(input.policy.totalCap) <= 0n) {
|
|
3322
|
+
throw new Error("create_spend_policy requires a non-zero total_cap");
|
|
3323
|
+
}
|
|
3324
|
+
if (!input.policy.maxPerPayment || BigInt(input.policy.maxPerPayment) <= 0n) {
|
|
3325
|
+
throw new Error("create_spend_policy requires a non-zero max_per_payment");
|
|
3326
|
+
}
|
|
3327
|
+
if (!input.grant.sessionCap || BigInt(input.grant.sessionCap) <= 0n) {
|
|
3328
|
+
throw new Error("create_grant requires a non-zero session_cap");
|
|
3329
|
+
}
|
|
3330
|
+
if (!input.grant.maxPerPayment || BigInt(input.grant.maxPerPayment) <= 0n) {
|
|
3331
|
+
throw new Error("create_grant requires a non-zero max_per_payment");
|
|
3332
|
+
}
|
|
3333
|
+
const tx = new Transaction2();
|
|
3334
|
+
tx.setSender(input.owner);
|
|
3335
|
+
const targetResults = input.policy.targets.map((t) => {
|
|
3336
|
+
const hash = targetHashBytes(t.targetHash);
|
|
3337
|
+
return tx.moveCall({
|
|
3338
|
+
target: target("new_policy_target"),
|
|
3339
|
+
arguments: [
|
|
3340
|
+
tx.pure.vector("u8", Array.from(hash)),
|
|
3341
|
+
tx.pure.address(t.recipient),
|
|
3342
|
+
tx.pure.u64(BigInt(t.maxPerPayment))
|
|
3343
|
+
]
|
|
3344
|
+
});
|
|
3345
|
+
});
|
|
3346
|
+
const targetsVec = tx.makeMoveVec({
|
|
3347
|
+
type: `${packageId}::${MODULE}::PolicyTarget`,
|
|
3348
|
+
elements: targetResults
|
|
3349
|
+
});
|
|
3350
|
+
const policyExpires = input.policy.expiresAtMs === void 0 || input.policy.expiresAtMs === null ? 0n : BigInt(input.policy.expiresAtMs);
|
|
3351
|
+
const policyIdResult = tx.moveCall({
|
|
3352
|
+
target: target("create_spend_policy"),
|
|
3353
|
+
typeArguments: [input.coinType],
|
|
3354
|
+
arguments: [
|
|
3355
|
+
tx.object(input.poolObjectId),
|
|
3356
|
+
targetsVec,
|
|
3357
|
+
tx.pure.u64(BigInt(input.policy.totalCap)),
|
|
3358
|
+
tx.pure.u64(BigInt(input.policy.maxPerPayment)),
|
|
3359
|
+
tx.pure.u64(policyExpires)
|
|
3360
|
+
]
|
|
3361
|
+
});
|
|
3362
|
+
const policyIdsVec = tx.makeMoveVec({
|
|
3363
|
+
type: "u64",
|
|
3364
|
+
elements: [policyIdResult]
|
|
3365
|
+
});
|
|
3366
|
+
const grantExpires = input.grant.expiresAtMs === void 0 || input.grant.expiresAtMs === null ? 0n : BigInt(input.grant.expiresAtMs);
|
|
3367
|
+
tx.moveCall({
|
|
3368
|
+
target: target("create_policy_grant"),
|
|
3369
|
+
typeArguments: [input.coinType],
|
|
3370
|
+
arguments: [
|
|
3371
|
+
tx.object(input.poolObjectId),
|
|
3372
|
+
tx.pure.address(input.delegate),
|
|
3373
|
+
tx.pure.option("u64", BigInt(input.grant.sessionCap)),
|
|
3374
|
+
tx.pure.option("u64", BigInt(input.grant.maxPerPayment)),
|
|
3375
|
+
tx.pure.u64(grantExpires),
|
|
3376
|
+
policyIdsVec
|
|
3377
|
+
]
|
|
3378
|
+
});
|
|
3379
|
+
return kindBytes(tx);
|
|
3380
|
+
},
|
|
2976
3381
|
async buildPausePolicyKind(input) {
|
|
2977
3382
|
const tx = new Transaction2();
|
|
2978
3383
|
tx.setSender(input.owner);
|
|
@@ -3312,6 +3717,24 @@ function createSpendAccountChain(options) {
|
|
|
3312
3717
|
return null;
|
|
3313
3718
|
}
|
|
3314
3719
|
},
|
|
3720
|
+
async readGrantLastChange(grantObjectId) {
|
|
3721
|
+
try {
|
|
3722
|
+
const { object } = await client.core.getObject({
|
|
3723
|
+
objectId: grantObjectId,
|
|
3724
|
+
include: { json: true, previousTransaction: true }
|
|
3725
|
+
});
|
|
3726
|
+
const json = object?.json;
|
|
3727
|
+
if (!json || typeof json.revoked !== "boolean")
|
|
3728
|
+
return null;
|
|
3729
|
+
const previous = object?.previousTransaction;
|
|
3730
|
+
return {
|
|
3731
|
+
revoked: json.revoked,
|
|
3732
|
+
previousTransaction: typeof previous === "string" && previous.trim() ? previous.trim() : null
|
|
3733
|
+
};
|
|
3734
|
+
} catch {
|
|
3735
|
+
return null;
|
|
3736
|
+
}
|
|
3737
|
+
},
|
|
3315
3738
|
async readPolicyBudget({ poolObjectId, onChainPolicyId }) {
|
|
3316
3739
|
try {
|
|
3317
3740
|
const response = await client.core.getDynamicField({
|
|
@@ -3436,13 +3859,18 @@ var GUARDED_DELEGATE_ARG_LAYOUT = {
|
|
|
3436
3859
|
recipient: null,
|
|
3437
3860
|
amount: 6,
|
|
3438
3861
|
paymentIdHash: 7,
|
|
3439
|
-
expiresAtMs: 9
|
|
3862
|
+
expiresAtMs: 9,
|
|
3863
|
+
// After clock (10): chain id, refund config, decide window, refund window.
|
|
3864
|
+
decideWindowMs: 13,
|
|
3865
|
+
refundWindowMs: 14
|
|
3440
3866
|
},
|
|
3441
3867
|
settle_any_recipient_to_refund_vault: {
|
|
3442
3868
|
recipient: 4,
|
|
3443
3869
|
amount: 5,
|
|
3444
3870
|
paymentIdHash: 6,
|
|
3445
|
-
expiresAtMs: 9
|
|
3871
|
+
expiresAtMs: 9,
|
|
3872
|
+
decideWindowMs: 13,
|
|
3873
|
+
refundWindowMs: 14
|
|
3446
3874
|
}
|
|
3447
3875
|
};
|
|
3448
3876
|
function pureBytesOf(data, arg) {
|
|
@@ -3522,11 +3950,48 @@ function recoverGuardedDelegateCalls(finalized) {
|
|
|
3522
3950
|
paymentIdHash: readPureVectorU8Hex(data, args[layout.paymentIdHash]),
|
|
3523
3951
|
amount: readPureU64(data, args[layout.amount]),
|
|
3524
3952
|
recipient: layout.recipient === null ? null : readPureAddress(data, args[layout.recipient]),
|
|
3525
|
-
expiresAtMs: readPureU64(data, args[layout.expiresAtMs])
|
|
3953
|
+
expiresAtMs: readPureU64(data, args[layout.expiresAtMs]),
|
|
3954
|
+
..."decideWindowMs" in layout ? {
|
|
3955
|
+
decideWindowMs: readPureU64(data, args[layout.decideWindowMs]),
|
|
3956
|
+
refundWindowMs: readPureU64(data, args[layout.refundWindowMs])
|
|
3957
|
+
} : {}
|
|
3526
3958
|
});
|
|
3527
3959
|
}
|
|
3528
3960
|
return calls;
|
|
3529
3961
|
}
|
|
3962
|
+
var VAULT_SETTLEMENT_TS_TIMEOUT_MS = 1e4;
|
|
3963
|
+
function withTimeout(work, ms, label) {
|
|
3964
|
+
return new Promise((resolve, reject2) => {
|
|
3965
|
+
const timer = setTimeout(() => reject2(new Error(`${label} timed out after ${ms}ms`)), ms);
|
|
3966
|
+
Promise.resolve(work).then((value) => {
|
|
3967
|
+
clearTimeout(timer);
|
|
3968
|
+
resolve(value);
|
|
3969
|
+
}, (err) => {
|
|
3970
|
+
clearTimeout(timer);
|
|
3971
|
+
reject2(err);
|
|
3972
|
+
});
|
|
3973
|
+
});
|
|
3974
|
+
}
|
|
3975
|
+
async function readVaultSettlementMs(client, digest) {
|
|
3976
|
+
const ledger = client.ledgerService;
|
|
3977
|
+
if (!ledger?.getTransaction)
|
|
3978
|
+
return void 0;
|
|
3979
|
+
try {
|
|
3980
|
+
const call = await withTimeout(ledger.getTransaction({
|
|
3981
|
+
digest,
|
|
3982
|
+
readMask: { paths: ["timestamp"] }
|
|
3983
|
+
}), VAULT_SETTLEMENT_TS_TIMEOUT_MS, "vault settlement timestamp read");
|
|
3984
|
+
const ts = call.response.transaction?.timestamp;
|
|
3985
|
+
if (!ts || ts.seconds === void 0)
|
|
3986
|
+
return void 0;
|
|
3987
|
+
const seconds = Number(ts.seconds);
|
|
3988
|
+
if (!Number.isFinite(seconds))
|
|
3989
|
+
return void 0;
|
|
3990
|
+
return seconds * 1e3 + Math.floor((ts.nanos ?? 0) / 1e6);
|
|
3991
|
+
} catch {
|
|
3992
|
+
return void 0;
|
|
3993
|
+
}
|
|
3994
|
+
}
|
|
3530
3995
|
function createSpendAccountSettledTxReader(options) {
|
|
3531
3996
|
const network = toGrpcNetwork(options.network);
|
|
3532
3997
|
const client = options.client ?? createFailoverGrpcClient({
|
|
@@ -3581,6 +4046,7 @@ function createSpendAccountSettledTxReader(options) {
|
|
|
3581
4046
|
kind: e.eventType.split("::").pop() ?? e.eventType
|
|
3582
4047
|
}));
|
|
3583
4048
|
const guardedDelegateCalls = recoverGuardedDelegateCalls(finalized);
|
|
4049
|
+
const timestampMs = events.some((event) => event.kind === "VaultOpened") ? await readVaultSettlementMs(client, digest) : void 0;
|
|
3584
4050
|
return {
|
|
3585
4051
|
status: "success",
|
|
3586
4052
|
txDigest: digest,
|
|
@@ -3588,7 +4054,8 @@ function createSpendAccountSettledTxReader(options) {
|
|
|
3588
4054
|
moveCalls,
|
|
3589
4055
|
objectIds,
|
|
3590
4056
|
events,
|
|
3591
|
-
guardedDelegateCalls
|
|
4057
|
+
guardedDelegateCalls,
|
|
4058
|
+
...timestampMs !== void 0 ? { timestampMs } : {}
|
|
3592
4059
|
};
|
|
3593
4060
|
}
|
|
3594
4061
|
};
|
|
@@ -3981,7 +4448,7 @@ var sha256 = /* @__PURE__ */ createHasher(
|
|
|
3981
4448
|
);
|
|
3982
4449
|
|
|
3983
4450
|
// ../sdk/dist/protocol/offer-exclusion.js
|
|
3984
|
-
import { normalizeStructTag as
|
|
4451
|
+
import { normalizeStructTag as normalizeStructTag7, normalizeSuiAddress as normalizeSuiAddress4 } from "@mysten/sui/utils";
|
|
3985
4452
|
|
|
3986
4453
|
// ../sdk/dist/protocol/terms.js
|
|
3987
4454
|
function paymentIdHash(challengeId) {
|
|
@@ -4056,7 +4523,7 @@ function addr32(address) {
|
|
|
4056
4523
|
return hexToBytes(normalized.slice(2));
|
|
4057
4524
|
}
|
|
4058
4525
|
function canonicalCoinTypeBytes(coinType) {
|
|
4059
|
-
const normalized =
|
|
4526
|
+
const normalized = normalizeStructTag7(coinType.trim());
|
|
4060
4527
|
const canonical = normalized.replace(/0x([0-9a-f]{64})/g, "$1");
|
|
4061
4528
|
if (!/^[0-9a-f]{64}::/.test(canonical)) {
|
|
4062
4529
|
throw new Error(`coin type must resolve to a numeric package address: ${coinType}`);
|
|
@@ -4256,7 +4723,7 @@ function createGrpcExclusionRegistryReader(client) {
|
|
|
4256
4723
|
// ../sdk/dist/delegated-signer/payer.js
|
|
4257
4724
|
import { bcs as bcs7 } from "@mysten/sui/bcs";
|
|
4258
4725
|
import { Transaction as Transaction4 } from "@mysten/sui/transactions";
|
|
4259
|
-
import { fromBase64 as fromBase647, normalizeStructTag as
|
|
4726
|
+
import { fromBase64 as fromBase647, normalizeStructTag as normalizeStructTag10, normalizeSuiAddress as normalizeSuiAddress9, toBase64 as toBase645 } from "@mysten/sui/utils";
|
|
4260
4727
|
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
4261
4728
|
|
|
4262
4729
|
// ../sdk/dist/delegated-signer/finality-poll.js
|
|
@@ -4282,7 +4749,7 @@ async function pollFinality(input) {
|
|
|
4282
4749
|
}
|
|
4283
4750
|
|
|
4284
4751
|
// ../sdk/dist/pay-operation/operation.js
|
|
4285
|
-
import { normalizeStructTag as
|
|
4752
|
+
import { normalizeStructTag as normalizeStructTag9, normalizeSuiAddress as normalizeSuiAddress6 } from "@mysten/sui/utils";
|
|
4286
4753
|
|
|
4287
4754
|
// ../core/dist/policy/grant-target.js
|
|
4288
4755
|
function normalizeHash(hex) {
|
|
@@ -4370,12 +4837,6 @@ import { fromBase64 as fromBase645, toBase64 as toBase643 } from "@mysten/sui/ut
|
|
|
4370
4837
|
|
|
4371
4838
|
// ../sdk/dist/protocol/auth-params.js
|
|
4372
4839
|
var TOKEN = /^[A-Za-z0-9!#$%&'*+\-.^_`|~]+$/;
|
|
4373
|
-
function formatAuthParams(params) {
|
|
4374
|
-
return Object.entries(params).map(([k, v]) => `${k}=${TOKEN.test(v) ? v : quote(v)}`).join(", ");
|
|
4375
|
-
}
|
|
4376
|
-
function quote(value) {
|
|
4377
|
-
return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
4378
|
-
}
|
|
4379
4840
|
function parseAuthHeader(header) {
|
|
4380
4841
|
const trimmed = header.trim();
|
|
4381
4842
|
const firstSpace = trimmed.indexOf(" ");
|
|
@@ -4454,6 +4915,19 @@ function bytesToBase64Url(bytes) {
|
|
|
4454
4915
|
const base64 = typeof globalThis.btoa === "function" ? globalThis.btoa(binary) : Buffer.from(bytes).toString("base64");
|
|
4455
4916
|
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
4456
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
|
+
}
|
|
4457
4931
|
|
|
4458
4932
|
// ../sdk/dist/protocol/challenge.js
|
|
4459
4933
|
import { Ed25519PublicKey } from "@mysten/sui/keypairs/ed25519";
|
|
@@ -4798,9 +5272,220 @@ function offerToBase64Url(offer) {
|
|
|
4798
5272
|
}
|
|
4799
5273
|
var MPP_SCHEME = "Payment";
|
|
4800
5274
|
var MPP_METHOD = "sui.charge";
|
|
5275
|
+
var MPP_SUI_METHOD = "sui";
|
|
5276
|
+
var MPP_CHARGE_INTENT = "charge";
|
|
5277
|
+
var MPP_RECEIPT_STATUS = "success";
|
|
5278
|
+
var LEGACY_RECEIPT_STATUS = "settled";
|
|
4801
5279
|
var MPP_CHALLENGE_HEADER = "WWW-Authenticate";
|
|
4802
5280
|
var MPP_CREDENTIAL_HEADER = "Authorization";
|
|
4803
5281
|
var MPP_RECEIPT_HEADER = "Payment-Receipt";
|
|
5282
|
+
var HEADER_TEXT_REPLACEMENTS = {
|
|
5283
|
+
"\u2264": "<=",
|
|
5284
|
+
// ≤ less-than-or-equal
|
|
5285
|
+
"\u2265": ">=",
|
|
5286
|
+
// ≥ greater-than-or-equal
|
|
5287
|
+
"\u2014": "-",
|
|
5288
|
+
// — em dash
|
|
5289
|
+
"\u2013": "-",
|
|
5290
|
+
// – en dash
|
|
5291
|
+
"\u2018": "'",
|
|
5292
|
+
// ' left single quote
|
|
5293
|
+
"\u2019": "'",
|
|
5294
|
+
// ' right single quote
|
|
5295
|
+
"\u201C": '"',
|
|
5296
|
+
// " left double quote
|
|
5297
|
+
"\u201D": '"'
|
|
5298
|
+
// " right double quote
|
|
5299
|
+
};
|
|
5300
|
+
function latin1HeaderText(value) {
|
|
5301
|
+
let out = "";
|
|
5302
|
+
for (const ch of value) {
|
|
5303
|
+
const mapped = HEADER_TEXT_REPLACEMENTS[ch];
|
|
5304
|
+
if (mapped !== void 0)
|
|
5305
|
+
out += mapped;
|
|
5306
|
+
else if (ch.codePointAt(0) > 255)
|
|
5307
|
+
out += "?";
|
|
5308
|
+
else
|
|
5309
|
+
out += ch;
|
|
5310
|
+
}
|
|
5311
|
+
return out;
|
|
5312
|
+
}
|
|
5313
|
+
var DAY_MS = 864e5;
|
|
5314
|
+
function billingPeriod(periodMs) {
|
|
5315
|
+
if (!Number.isInteger(periodMs) || periodMs < DAY_MS || periodMs % DAY_MS !== 0)
|
|
5316
|
+
return null;
|
|
5317
|
+
const days = periodMs / DAY_MS;
|
|
5318
|
+
if (days % 7 === 0)
|
|
5319
|
+
return { periodCount: String(days / 7), periodUnit: "week" };
|
|
5320
|
+
return { periodCount: String(days), periodUnit: "day" };
|
|
5321
|
+
}
|
|
5322
|
+
function billingPeriodMs(unit, count) {
|
|
5323
|
+
if (!Number.isInteger(count) || count <= 0)
|
|
5324
|
+
return null;
|
|
5325
|
+
if (unit === "day")
|
|
5326
|
+
return count * DAY_MS;
|
|
5327
|
+
if (unit === "week")
|
|
5328
|
+
return count * 7 * DAY_MS;
|
|
5329
|
+
return null;
|
|
5330
|
+
}
|
|
5331
|
+
function expiresWire(offer) {
|
|
5332
|
+
if (typeof offer.expiresAt !== "number" || !Number.isFinite(offer.expiresAt))
|
|
5333
|
+
return void 0;
|
|
5334
|
+
return new Date(offer.expiresAt).toISOString();
|
|
5335
|
+
}
|
|
5336
|
+
function flatParams(offer) {
|
|
5337
|
+
const params = {
|
|
5338
|
+
amount: offer.amount,
|
|
5339
|
+
asset: offer.asset,
|
|
5340
|
+
network: offer.network,
|
|
5341
|
+
recipient: offer.payTo,
|
|
5342
|
+
package: offer.packageId,
|
|
5343
|
+
resource: offer.resource,
|
|
5344
|
+
digest: offer.digest
|
|
5345
|
+
};
|
|
5346
|
+
if (typeof offer.decimals === "number")
|
|
5347
|
+
params.decimals = String(offer.decimals);
|
|
5348
|
+
if (typeof offer.description === "string") {
|
|
5349
|
+
params.description = latin1HeaderText(offer.description);
|
|
5350
|
+
}
|
|
5351
|
+
if (typeof offer.issuedAt === "number" && Number.isFinite(offer.issuedAt)) {
|
|
5352
|
+
params.issued = new Date(offer.issuedAt).toISOString();
|
|
5353
|
+
}
|
|
5354
|
+
if (typeof offer.expiresAt === "number" && Number.isFinite(offer.expiresAt)) {
|
|
5355
|
+
params.expires = new Date(offer.expiresAt).toISOString();
|
|
5356
|
+
}
|
|
5357
|
+
if (offer.netAmount !== void 0)
|
|
5358
|
+
params.net_amount = offer.netAmount;
|
|
5359
|
+
if (offer.platformFee !== void 0)
|
|
5360
|
+
params.platform_fee = offer.platformFee;
|
|
5361
|
+
if (offer.digestVersion !== void 0)
|
|
5362
|
+
params.digest_version = String(offer.digestVersion);
|
|
5363
|
+
if (offer.settlementRail !== void 0)
|
|
5364
|
+
params.settlement_rail = offer.settlementRail;
|
|
5365
|
+
if (offer.serviceId !== void 0)
|
|
5366
|
+
params.service_id = offer.serviceId;
|
|
5367
|
+
if (offer.serviceRevision !== void 0) {
|
|
5368
|
+
params.service_revision = String(offer.serviceRevision);
|
|
5369
|
+
}
|
|
5370
|
+
if (offer.targetHash !== void 0)
|
|
5371
|
+
params.target_hash = offer.targetHash;
|
|
5372
|
+
if (offer.authorizationEpoch !== void 0) {
|
|
5373
|
+
params.authorization_epoch = String(offer.authorizationEpoch);
|
|
5374
|
+
}
|
|
5375
|
+
if (offer.method !== void 0)
|
|
5376
|
+
params.http_method = offer.method;
|
|
5377
|
+
if (offer.path !== void 0)
|
|
5378
|
+
params.http_path = offer.path;
|
|
5379
|
+
if (offer.bodyHash !== void 0)
|
|
5380
|
+
params.body_hash = offer.bodyHash;
|
|
5381
|
+
if (offer.contentType !== void 0)
|
|
5382
|
+
params.content_type = offer.contentType;
|
|
5383
|
+
if (offer.intent !== void 0)
|
|
5384
|
+
params.intent = offer.intent;
|
|
5385
|
+
if (offer.periodMs !== void 0)
|
|
5386
|
+
params.period_ms = String(offer.periodMs);
|
|
5387
|
+
if (offer.periodCount !== void 0)
|
|
5388
|
+
params.period_count = String(offer.periodCount);
|
|
5389
|
+
if (offer.refundable !== void 0)
|
|
5390
|
+
params.refundable = offer.refundable ? "true" : "false";
|
|
5391
|
+
if (offer.refundWindowMs !== void 0) {
|
|
5392
|
+
params.refund_window_ms = String(offer.refundWindowMs);
|
|
5393
|
+
}
|
|
5394
|
+
if (offer.decideWindowMs !== void 0) {
|
|
5395
|
+
params.decide_window_ms = String(offer.decideWindowMs);
|
|
5396
|
+
}
|
|
5397
|
+
if (offer.chainId !== void 0)
|
|
5398
|
+
params.chain_id = String(offer.chainId);
|
|
5399
|
+
if (offer.paymentSalt !== void 0)
|
|
5400
|
+
params.payment_salt = offer.paymentSalt;
|
|
5401
|
+
if (offer.refundConfigId !== void 0)
|
|
5402
|
+
params.refund_config_id = offer.refundConfigId;
|
|
5403
|
+
if (offer.refundTo !== void 0)
|
|
5404
|
+
params.refund_to = offer.refundTo;
|
|
5405
|
+
if (offer.sponsorGasOwner !== void 0) {
|
|
5406
|
+
params.sponsor_gas_owner = offer.sponsorGasOwner;
|
|
5407
|
+
}
|
|
5408
|
+
if (offer.sponsorGasBudget !== void 0) {
|
|
5409
|
+
params.sponsor_gas_budget = offer.sponsorGasBudget;
|
|
5410
|
+
}
|
|
5411
|
+
if (offer.sponsorGasPrice !== void 0) {
|
|
5412
|
+
params.sponsor_gas_price = offer.sponsorGasPrice;
|
|
5413
|
+
}
|
|
5414
|
+
if (offer.sponsorGasPayment !== void 0) {
|
|
5415
|
+
params.sponsor_gas_payment = offer.sponsorGasPayment;
|
|
5416
|
+
}
|
|
5417
|
+
if (offer.acceptedRails !== void 0) {
|
|
5418
|
+
params.accepted_rails = offer.acceptedRails.join(",");
|
|
5419
|
+
}
|
|
5420
|
+
if (offer.exclusionProtocolVersion !== void 0) {
|
|
5421
|
+
params.exclusion_protocol_version = String(offer.exclusionProtocolVersion);
|
|
5422
|
+
}
|
|
5423
|
+
if (offer.registryIdentity !== void 0) {
|
|
5424
|
+
params.registry_identity = offer.registryIdentity;
|
|
5425
|
+
}
|
|
5426
|
+
if (offer.sig !== void 0)
|
|
5427
|
+
params.sig = offer.sig;
|
|
5428
|
+
if (offer.sigKid !== void 0)
|
|
5429
|
+
params.sig_kid = offer.sigKid;
|
|
5430
|
+
return params;
|
|
5431
|
+
}
|
|
5432
|
+
function legacyRequestBlob(offer, copies = false) {
|
|
5433
|
+
const params = flatParams(offer);
|
|
5434
|
+
if (copies) {
|
|
5435
|
+
params.method = MPP_SUI_METHOD;
|
|
5436
|
+
params.realm = "suipay";
|
|
5437
|
+
params.challenge = offer.challengeId;
|
|
5438
|
+
if (typeof offer.mimeType === "string")
|
|
5439
|
+
params.type = offer.mimeType;
|
|
5440
|
+
}
|
|
5441
|
+
return bytesToBase64Url(new TextEncoder().encode(canonicalJson(params)));
|
|
5442
|
+
}
|
|
5443
|
+
function requestBlob(offer) {
|
|
5444
|
+
const flat = flatParams(offer);
|
|
5445
|
+
const details = { ...flat };
|
|
5446
|
+
delete details.amount;
|
|
5447
|
+
delete details.asset;
|
|
5448
|
+
delete details.recipient;
|
|
5449
|
+
delete details.description;
|
|
5450
|
+
delete details.expires;
|
|
5451
|
+
const body = {
|
|
5452
|
+
amount: flat.amount,
|
|
5453
|
+
currency: flat.asset,
|
|
5454
|
+
methodDetails: details
|
|
5455
|
+
};
|
|
5456
|
+
if (flat.recipient !== void 0)
|
|
5457
|
+
body.recipient = flat.recipient;
|
|
5458
|
+
if (flat.description !== void 0)
|
|
5459
|
+
body.description = flat.description;
|
|
5460
|
+
if (wireIntent(offer) === "subscription") {
|
|
5461
|
+
delete details.period_ms;
|
|
5462
|
+
const periodMs = offer.periodMs;
|
|
5463
|
+
const billing = typeof periodMs === "number" ? billingPeriod(periodMs) : null;
|
|
5464
|
+
if (!billing) {
|
|
5465
|
+
throw new Error("subscription periodMs is not an exact number of days");
|
|
5466
|
+
}
|
|
5467
|
+
body.periodCount = billing.periodCount;
|
|
5468
|
+
body.periodUnit = billing.periodUnit;
|
|
5469
|
+
const periodCount = offer.periodCount;
|
|
5470
|
+
const issuedAt = offer.issuedAt;
|
|
5471
|
+
if (typeof periodMs === "number" && typeof periodCount === "number" && typeof issuedAt === "number" && Number.isSafeInteger(periodMs) && Number.isSafeInteger(periodCount) && Number.isSafeInteger(issuedAt) && Number.isSafeInteger(periodMs * periodCount)) {
|
|
5472
|
+
const end = issuedAt + periodMs * periodCount;
|
|
5473
|
+
if (Number.isSafeInteger(end))
|
|
5474
|
+
body.subscriptionExpires = new Date(end).toISOString();
|
|
5475
|
+
}
|
|
5476
|
+
}
|
|
5477
|
+
return bytesToBase64Url(new TextEncoder().encode(canonicalJsonValue(body)));
|
|
5478
|
+
}
|
|
5479
|
+
function issuedRequestBlob(offer) {
|
|
5480
|
+
return requestBlob(offer);
|
|
5481
|
+
}
|
|
5482
|
+
function echoedRequestBlob(offer) {
|
|
5483
|
+
try {
|
|
5484
|
+
return issuedRequestBlob(offer);
|
|
5485
|
+
} catch {
|
|
5486
|
+
return legacyRequestBlob(offer);
|
|
5487
|
+
}
|
|
5488
|
+
}
|
|
4804
5489
|
function splitChallenges(header) {
|
|
4805
5490
|
const scheme = `${MPP_SCHEME} `;
|
|
4806
5491
|
const value = header.trim();
|
|
@@ -4860,11 +5545,120 @@ function decodeChallenge(header, opts) {
|
|
|
4860
5545
|
}
|
|
4861
5546
|
return null;
|
|
4862
5547
|
}
|
|
5548
|
+
function canonicalJson(fields) {
|
|
5549
|
+
const keys = Object.keys(fields).sort();
|
|
5550
|
+
return `{${keys.map((key) => `${JSON.stringify(key)}:${JSON.stringify(fields[key])}`).join(",")}}`;
|
|
5551
|
+
}
|
|
5552
|
+
function canonicalJsonValue(value) {
|
|
5553
|
+
if (value === null || typeof value !== "object")
|
|
5554
|
+
return JSON.stringify(value);
|
|
5555
|
+
if (Array.isArray(value))
|
|
5556
|
+
return `[${value.map(canonicalJsonValue).join(",")}]`;
|
|
5557
|
+
const fields = value;
|
|
5558
|
+
const keys = Object.keys(fields).sort();
|
|
5559
|
+
return `{${keys.map((key) => `${JSON.stringify(key)}:${canonicalJsonValue(fields[key])}`).join(",")}}`;
|
|
5560
|
+
}
|
|
5561
|
+
function wireIntent(offer) {
|
|
5562
|
+
return offer.intent === "subscription" ? "subscription" : MPP_CHARGE_INTENT;
|
|
5563
|
+
}
|
|
5564
|
+
var REQUEST_TOP_LEVEL = /* @__PURE__ */ new Set([
|
|
5565
|
+
"amount",
|
|
5566
|
+
"asset",
|
|
5567
|
+
"currency",
|
|
5568
|
+
"description",
|
|
5569
|
+
"externalId",
|
|
5570
|
+
"recipient",
|
|
5571
|
+
"subscriptionExpires"
|
|
5572
|
+
]);
|
|
5573
|
+
function takeStrings(source, into) {
|
|
5574
|
+
for (const [key, value] of Object.entries(source)) {
|
|
5575
|
+
if (typeof value !== "string")
|
|
5576
|
+
return false;
|
|
5577
|
+
into[key] = value;
|
|
5578
|
+
}
|
|
5579
|
+
return true;
|
|
5580
|
+
}
|
|
5581
|
+
function officialParams(params) {
|
|
5582
|
+
if (params.method !== MPP_SUI_METHOD || !params.request)
|
|
5583
|
+
return null;
|
|
5584
|
+
if (params.intent !== MPP_CHARGE_INTENT && params.intent !== "subscription")
|
|
5585
|
+
return null;
|
|
5586
|
+
let body;
|
|
5587
|
+
try {
|
|
5588
|
+
body = JSON.parse(new TextDecoder().decode(bytesFromBase64Url(params.request)));
|
|
5589
|
+
} catch {
|
|
5590
|
+
return null;
|
|
5591
|
+
}
|
|
5592
|
+
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
5593
|
+
return null;
|
|
5594
|
+
const record = body;
|
|
5595
|
+
const fields = {};
|
|
5596
|
+
const details = record.methodDetails;
|
|
5597
|
+
if (details !== void 0) {
|
|
5598
|
+
if (!details || typeof details !== "object" || Array.isArray(details))
|
|
5599
|
+
return null;
|
|
5600
|
+
if (!takeStrings(details, fields))
|
|
5601
|
+
return null;
|
|
5602
|
+
for (const [key, value] of Object.entries(record)) {
|
|
5603
|
+
if (key === "methodDetails" || key === "periodCount" || key === "periodUnit")
|
|
5604
|
+
continue;
|
|
5605
|
+
if (typeof value !== "string" || !REQUEST_TOP_LEVEL.has(key))
|
|
5606
|
+
return null;
|
|
5607
|
+
if (fields[key] !== void 0 && fields[key] !== value)
|
|
5608
|
+
return null;
|
|
5609
|
+
fields[key] = value;
|
|
5610
|
+
}
|
|
5611
|
+
const periodCount = record.periodCount;
|
|
5612
|
+
const periodUnit = record.periodUnit;
|
|
5613
|
+
if (periodCount !== void 0 || periodUnit !== void 0) {
|
|
5614
|
+
if (typeof periodCount !== "string" || typeof periodUnit !== "string")
|
|
5615
|
+
return null;
|
|
5616
|
+
if (!/^[1-9]\d*$/.test(periodCount))
|
|
5617
|
+
return null;
|
|
5618
|
+
const ms = billingPeriodMs(periodUnit, Number(periodCount));
|
|
5619
|
+
if (ms === null)
|
|
5620
|
+
return null;
|
|
5621
|
+
if (fields.period_ms !== void 0 && fields.period_ms !== String(ms))
|
|
5622
|
+
return null;
|
|
5623
|
+
fields.period_ms = String(ms);
|
|
5624
|
+
}
|
|
5625
|
+
if (params.intent === "subscription" && fields.period_ms === void 0)
|
|
5626
|
+
return null;
|
|
5627
|
+
} else if (!takeStrings(record, fields)) {
|
|
5628
|
+
return null;
|
|
5629
|
+
}
|
|
5630
|
+
if (fields.currency !== void 0) {
|
|
5631
|
+
if (fields.asset !== void 0 && fields.asset !== fields.currency)
|
|
5632
|
+
return null;
|
|
5633
|
+
fields.asset = fields.currency;
|
|
5634
|
+
}
|
|
5635
|
+
if (params.expires !== void 0) {
|
|
5636
|
+
if (fields.expires !== void 0 && fields.expires !== params.expires)
|
|
5637
|
+
return null;
|
|
5638
|
+
if (fields.expires === void 0)
|
|
5639
|
+
fields.expires = params.expires;
|
|
5640
|
+
}
|
|
5641
|
+
if (!fields.challenge && params.id)
|
|
5642
|
+
fields.challenge = params.id;
|
|
5643
|
+
if (fields.method === void 0)
|
|
5644
|
+
fields.method = MPP_SUI_METHOD;
|
|
5645
|
+
if (fields.method !== MPP_METHOD && fields.method !== MPP_SUI_METHOD)
|
|
5646
|
+
return null;
|
|
5647
|
+
if (fields.intent !== void 0 && fields.intent !== params.intent)
|
|
5648
|
+
return null;
|
|
5649
|
+
if (fields.intent === void 0 && params.intent === "subscription")
|
|
5650
|
+
return null;
|
|
5651
|
+
fields.method = MPP_METHOD;
|
|
5652
|
+
return fields;
|
|
5653
|
+
}
|
|
4863
5654
|
function decodeSingleChallenge(header) {
|
|
4864
5655
|
const parsed = parseAuthHeader(header);
|
|
4865
5656
|
if (!parsed || parsed.scheme !== MPP_SCHEME)
|
|
4866
5657
|
return null;
|
|
4867
|
-
const
|
|
5658
|
+
const pinned = officialParams(parsed.params);
|
|
5659
|
+
const p = { ...pinned ?? parsed.params };
|
|
5660
|
+
if (p.method === MPP_SUI_METHOD)
|
|
5661
|
+
p.method = MPP_METHOD;
|
|
4868
5662
|
if (p.method !== MPP_METHOD)
|
|
4869
5663
|
return null;
|
|
4870
5664
|
const required = [
|
|
@@ -4949,13 +5743,15 @@ function decodeSingleChallenge(header) {
|
|
|
4949
5743
|
offer.intent = p.intent;
|
|
4950
5744
|
if (p.period_ms !== void 0) {
|
|
4951
5745
|
const ms = Number(p.period_ms);
|
|
4952
|
-
if (Number.
|
|
4953
|
-
|
|
5746
|
+
if (!Number.isSafeInteger(ms) || ms <= 0)
|
|
5747
|
+
return null;
|
|
5748
|
+
offer.periodMs = ms;
|
|
4954
5749
|
}
|
|
4955
5750
|
if (p.period_count !== void 0) {
|
|
4956
5751
|
const count = Number(p.period_count);
|
|
4957
|
-
if (Number.
|
|
4958
|
-
|
|
5752
|
+
if (!Number.isSafeInteger(count) || count <= 0)
|
|
5753
|
+
return null;
|
|
5754
|
+
offer.periodCount = count;
|
|
4959
5755
|
}
|
|
4960
5756
|
if (p.refundable === "true")
|
|
4961
5757
|
offer.refundable = true;
|
|
@@ -5015,25 +5811,46 @@ function decodeSingleChallenge(header) {
|
|
|
5015
5811
|
offer.sigKid = p.sig_kid;
|
|
5016
5812
|
return offer;
|
|
5017
5813
|
}
|
|
5814
|
+
function echoedChallenge(offer, challengeId) {
|
|
5815
|
+
const challenge = {
|
|
5816
|
+
id: challengeId,
|
|
5817
|
+
realm: "suipay",
|
|
5818
|
+
method: MPP_SUI_METHOD,
|
|
5819
|
+
intent: wireIntent(offer),
|
|
5820
|
+
// Section 5.2 echoes the original challenge, including its request.
|
|
5821
|
+
request: echoedRequestBlob(offer)
|
|
5822
|
+
};
|
|
5823
|
+
const expires = expiresWire(offer);
|
|
5824
|
+
if (expires !== void 0)
|
|
5825
|
+
challenge.expires = expires;
|
|
5826
|
+
return challenge;
|
|
5827
|
+
}
|
|
5828
|
+
function encodeOfficialMessage(body) {
|
|
5829
|
+
return `${MPP_SCHEME} ${bytesToBase64Url(new TextEncoder().encode(canonicalJsonValue(body)))}`;
|
|
5830
|
+
}
|
|
5018
5831
|
function encodeProof(proof) {
|
|
5019
|
-
return
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5832
|
+
return encodeOfficialMessage({
|
|
5833
|
+
challenge: echoedChallenge(proof.offer, proof.challengeId),
|
|
5834
|
+
payload: {
|
|
5835
|
+
payer: proof.payer,
|
|
5836
|
+
offer: offerToBase64Url(proof.offer),
|
|
5837
|
+
digest: proof.txDigest
|
|
5838
|
+
}
|
|
5839
|
+
});
|
|
5026
5840
|
}
|
|
5027
|
-
function
|
|
5028
|
-
|
|
5029
|
-
|
|
5841
|
+
function receiptFromParams(p) {
|
|
5842
|
+
if (p.method !== MPP_METHOD && p.method !== MPP_SUI_METHOD)
|
|
5843
|
+
return null;
|
|
5844
|
+
if (p.status !== MPP_RECEIPT_STATUS && p.status !== LEGACY_RECEIPT_STATUS)
|
|
5030
5845
|
return null;
|
|
5031
|
-
|
|
5032
|
-
|
|
5846
|
+
if (p.tx_digest && p.reference && p.tx_digest !== p.reference)
|
|
5847
|
+
return null;
|
|
5848
|
+
const txDigest = p.tx_digest || p.reference;
|
|
5849
|
+
if (!p.challenge || !txDigest || !p.payer || !p.amount || !p.asset || !p.network)
|
|
5033
5850
|
return null;
|
|
5034
5851
|
const receipt = {
|
|
5035
5852
|
challengeId: p.challenge,
|
|
5036
|
-
txDigest
|
|
5853
|
+
txDigest,
|
|
5037
5854
|
network: p.network,
|
|
5038
5855
|
payer: p.payer,
|
|
5039
5856
|
amount: p.amount,
|
|
@@ -5054,6 +5871,34 @@ function decodeReceipt(header) {
|
|
|
5054
5871
|
receipt.periodIndex = p.period_index;
|
|
5055
5872
|
return receipt;
|
|
5056
5873
|
}
|
|
5874
|
+
function decodeOfficialReceipt(header) {
|
|
5875
|
+
const token = header.trim();
|
|
5876
|
+
if (!/^[A-Za-z0-9_-]+$/.test(token))
|
|
5877
|
+
return null;
|
|
5878
|
+
let body;
|
|
5879
|
+
try {
|
|
5880
|
+
body = JSON.parse(new TextDecoder().decode(bytesFromBase64Url(token)));
|
|
5881
|
+
} catch {
|
|
5882
|
+
return null;
|
|
5883
|
+
}
|
|
5884
|
+
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
5885
|
+
return null;
|
|
5886
|
+
const fields = {};
|
|
5887
|
+
for (const [key, value] of Object.entries(body)) {
|
|
5888
|
+
if (typeof value !== "string")
|
|
5889
|
+
return null;
|
|
5890
|
+
fields[key] = value;
|
|
5891
|
+
}
|
|
5892
|
+
return receiptFromParams(fields);
|
|
5893
|
+
}
|
|
5894
|
+
function decodeReceipt(header) {
|
|
5895
|
+
if (/^[A-Za-z0-9_-]+$/.test(header.trim()))
|
|
5896
|
+
return decodeOfficialReceipt(header);
|
|
5897
|
+
const parsed = parseAuthHeader(`X ${header}`);
|
|
5898
|
+
if (!parsed)
|
|
5899
|
+
return null;
|
|
5900
|
+
return receiptFromParams(parsed.params);
|
|
5901
|
+
}
|
|
5057
5902
|
|
|
5058
5903
|
// ../sdk/dist/protocol/x402.js
|
|
5059
5904
|
import { fromBase64 as fromBase644, toBase64 as toBase642 } from "@mysten/sui/utils";
|
|
@@ -5511,7 +6356,7 @@ import { fromHex } from "@mysten/sui/utils";
|
|
|
5511
6356
|
|
|
5512
6357
|
// ../sdk/dist/protocol/coin-type-hash.js
|
|
5513
6358
|
import { createHash as createHash2 } from "crypto";
|
|
5514
|
-
import { normalizeStructTag as
|
|
6359
|
+
import { normalizeStructTag as normalizeStructTag8 } from "@mysten/sui/utils";
|
|
5515
6360
|
|
|
5516
6361
|
// ../sdk/dist/protocol/refund-vault.js
|
|
5517
6362
|
function isRefundableOffer(offer) {
|
|
@@ -6176,8 +7021,8 @@ function resolveAuthority(authority, offer) {
|
|
|
6176
7021
|
};
|
|
6177
7022
|
}
|
|
6178
7023
|
function validateAmount(offer, resolved) {
|
|
6179
|
-
const offerCoinType =
|
|
6180
|
-
const grantCoinType =
|
|
7024
|
+
const offerCoinType = normalizeStructTag9(offer.asset);
|
|
7025
|
+
const grantCoinType = normalizeStructTag9(resolved.coinType);
|
|
6181
7026
|
if (offerCoinType !== grantCoinType) {
|
|
6182
7027
|
return {
|
|
6183
7028
|
code: PAY_OPERATION_ERROR_CODES.COIN_TYPE_MISMATCH,
|
|
@@ -7248,7 +8093,7 @@ function atomicAmount(value) {
|
|
|
7248
8093
|
}
|
|
7249
8094
|
function sameStructTag(a, b) {
|
|
7250
8095
|
try {
|
|
7251
|
-
return
|
|
8096
|
+
return normalizeStructTag10(a) === normalizeStructTag10(b);
|
|
7252
8097
|
} catch {
|
|
7253
8098
|
return false;
|
|
7254
8099
|
}
|
|
@@ -8006,7 +8851,7 @@ async function payDelegatedSpendAccount(args) {
|
|
|
8006
8851
|
refuseOffer("POLICY_NO_TARGET");
|
|
8007
8852
|
}
|
|
8008
8853
|
try {
|
|
8009
|
-
|
|
8854
|
+
normalizeStructTag10(offer2.asset);
|
|
8010
8855
|
} catch {
|
|
8011
8856
|
refuseOffer("POLICY_BAD_ASSET");
|
|
8012
8857
|
}
|
|
@@ -8070,7 +8915,7 @@ async function payDelegatedSpendAccount(args) {
|
|
|
8070
8915
|
return buildSpendAccountPayKind(kindInput);
|
|
8071
8916
|
};
|
|
8072
8917
|
try {
|
|
8073
|
-
|
|
8918
|
+
normalizeStructTag10(snapshot.coinType);
|
|
8074
8919
|
} catch {
|
|
8075
8920
|
return failed("POLICY_REJECTED", PUBLIC_DETAIL.POLICY_REJECTED);
|
|
8076
8921
|
}
|
|
@@ -9669,7 +10514,9 @@ async function resolvePayerSession(options) {
|
|
|
9669
10514
|
ok: false,
|
|
9670
10515
|
// The gateway's stable code, never a raw body — the read client already
|
|
9671
10516
|
// sanitized it, and an operator needs to tell 429 from 401.
|
|
9672
|
-
|
|
10517
|
+
// A 429 is the gateway's rate limit, not a manifest the agent can fix, so
|
|
10518
|
+
// it keeps the retryable code instead of the manifest default.
|
|
10519
|
+
error: manifestError(MANIFEST_ERROR_CODES.MALFORMED_MANIFEST, `bootstrap was refused (${bootstrap.error}${bootstrap.code ? `: ${bootstrap.code}` : ""})`, bootstrap.status === 429 ? "limit.rate_limited" : void 0)
|
|
9673
10520
|
};
|
|
9674
10521
|
}
|
|
9675
10522
|
const whole = manifestToSession({
|
|
@@ -9927,8 +10774,44 @@ async function createPayer(options) {
|
|
|
9927
10774
|
value: { address, deployment, grant: binding, session, pay, verifySettlement }
|
|
9928
10775
|
};
|
|
9929
10776
|
}
|
|
10777
|
+
|
|
10778
|
+
// ../sdk/dist/oauth/delegate-proof.js
|
|
10779
|
+
import { normalizeSuiAddress as normalizeSuiAddress12 } from "@mysten/sui/utils";
|
|
10780
|
+
import { verifyPersonalMessageSignature as verifyPersonalMessageSignature3 } from "@mysten/sui/verify";
|
|
10781
|
+
var OAUTH_DELEGATE_PROOF_TTL_MS = 15 * 6e4;
|
|
10782
|
+
function encodeOAuthDelegateProof(binding, expiresAtMs, ownerAddress) {
|
|
10783
|
+
if (!binding.delegateAddress || !Number.isSafeInteger(expiresAtMs) || expiresAtMs <= 0) {
|
|
10784
|
+
throw new Error("Invalid delegate proof binding.");
|
|
10785
|
+
}
|
|
10786
|
+
return new TextEncoder().encode(JSON.stringify([
|
|
10787
|
+
"suipay:oauth-delegate:v1",
|
|
10788
|
+
binding.clientId,
|
|
10789
|
+
binding.redirectUri,
|
|
10790
|
+
binding.resource,
|
|
10791
|
+
binding.scope,
|
|
10792
|
+
binding.codeChallenge,
|
|
10793
|
+
normalizeSuiAddress12(binding.delegateAddress),
|
|
10794
|
+
normalizeSuiAddress12(ownerAddress),
|
|
10795
|
+
expiresAtMs
|
|
10796
|
+
]));
|
|
10797
|
+
}
|
|
10798
|
+
async function verifyOAuthDelegateProof(binding, proof, nowMs = Date.now(), expectedOwner) {
|
|
10799
|
+
try {
|
|
10800
|
+
const p = proof;
|
|
10801
|
+
const message = encodeOAuthDelegateProof(binding, p.expiresAtMs, p.ownerAddress);
|
|
10802
|
+
if (typeof p.signature !== "string" || p.signature.length > 8192 || p.expiresAtMs <= nowMs || p.expiresAtMs > nowMs + OAUTH_DELEGATE_PROOF_TTL_MS)
|
|
10803
|
+
return false;
|
|
10804
|
+
if (expectedOwner && normalizeSuiAddress12(p.ownerAddress) !== normalizeSuiAddress12(expectedOwner))
|
|
10805
|
+
return false;
|
|
10806
|
+
const publicKey = await verifyPersonalMessageSignature3(message, p.signature);
|
|
10807
|
+
return publicKey.toSuiAddress() === normalizeSuiAddress12(binding.delegateAddress);
|
|
10808
|
+
} catch {
|
|
10809
|
+
return false;
|
|
10810
|
+
}
|
|
10811
|
+
}
|
|
9930
10812
|
export {
|
|
9931
10813
|
NativeTransferError,
|
|
10814
|
+
OAUTH_DELEGATE_PROOF_TTL_MS,
|
|
9932
10815
|
SuiPayError,
|
|
9933
10816
|
buildMcpPaymentPayload,
|
|
9934
10817
|
buildNativeTransferBytes,
|
|
@@ -9939,10 +10822,12 @@ export {
|
|
|
9939
10822
|
createPayer,
|
|
9940
10823
|
createReader,
|
|
9941
10824
|
dashboardManifestToAgentManifest,
|
|
10825
|
+
encodeOAuthDelegateProof,
|
|
9942
10826
|
inspectNativeTransfer,
|
|
9943
10827
|
manifestToSession,
|
|
9944
10828
|
parseAgentManifest,
|
|
9945
10829
|
personalMessageSigner,
|
|
9946
10830
|
toErrorFields,
|
|
10831
|
+
verifyOAuthDelegateProof,
|
|
9947
10832
|
verifyPreparedPayment
|
|
9948
10833
|
};
|