@mysten-incubation/suipay-buyer 0.4.0-dev.1 → 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.
Files changed (2) hide show
  1. package/dist/index.js +70 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3180,6 +3180,38 @@ function createSpendAccountChain(options) {
3180
3180
  });
3181
3181
  const packageId = normalizeSuiAddress3(options.packageId);
3182
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
+ }
3183
3215
  async function kindBytes(tx) {
3184
3216
  return {
3185
3217
  kindBytes: toBase64(await tx.build({ client, onlyTransactionKind: true }))
@@ -3788,6 +3820,44 @@ function createSpendAccountChain(options) {
3788
3820
  return null;
3789
3821
  }
3790
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
+ },
3791
3861
  async readPolicyBudget({ poolObjectId, onChainPolicyId }) {
3792
3862
  try {
3793
3863
  const response = await client.core.getDynamicField({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mysten-incubation/suipay-buyer",
3
- "version": "0.4.0-dev.1",
3
+ "version": "0.4.0-dev.2",
4
4
  "type": "module",
5
5
  "description": "SuiPay buyer SDK — delegated spend-account pay plus a typed /v1 control-plane client.",
6
6
  "license": "MIT",