@haneullabs/haneul 2.4.0 → 2.5.1

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 (95) hide show
  1. package/dist/bcs/bcs.d.mts +6 -6
  2. package/dist/bcs/bcs.mjs +1 -1
  3. package/dist/bcs/bcs.mjs.map +1 -1
  4. package/dist/bcs/index.d.mts +4 -4
  5. package/dist/client/core-resolver.mjs +2 -2
  6. package/dist/client/core-resolver.mjs.map +1 -1
  7. package/dist/client/core.mjs +1 -1
  8. package/dist/client/core.mjs.map +1 -1
  9. package/dist/cryptography/keypair.d.mts +1 -1
  10. package/dist/cryptography/keypair.mjs +3 -3
  11. package/dist/cryptography/keypair.mjs.map +1 -1
  12. package/dist/cryptography/publickey.d.mts +1 -1
  13. package/dist/cryptography/publickey.mjs +2 -2
  14. package/dist/cryptography/publickey.mjs.map +1 -1
  15. package/dist/cryptography/signature.d.mts +6 -6
  16. package/dist/grpc/proto/haneul/rpc/v2/ledger_service.client.d.mts +4 -4
  17. package/dist/grpc/proto/haneul/rpc/v2/name_service.client.d.mts +4 -4
  18. package/dist/grpc/proto/haneul/rpc/v2/signature_verification_service.client.d.mts +4 -4
  19. package/dist/grpc/proto/haneul/rpc/v2/state_service.client.d.mts +4 -4
  20. package/dist/grpc/proto/haneul/rpc/v2/subscription_service.client.d.mts +4 -4
  21. package/dist/grpc/proto/haneul/rpc/v2/system_state.d.mts +2 -2
  22. package/dist/grpc/proto/haneul/rpc/v2/system_state.mjs +1 -1
  23. package/dist/grpc/proto/haneul/rpc/v2/system_state.mjs.map +1 -1
  24. package/dist/grpc/proto/haneul/rpc/v2/transaction_execution_service.client.d.mts +4 -4
  25. package/dist/jsonRpc/client.d.mts +5 -5
  26. package/dist/jsonRpc/client.d.mts.map +1 -1
  27. package/dist/jsonRpc/client.mjs +56 -56
  28. package/dist/jsonRpc/client.mjs.map +1 -1
  29. package/dist/jsonRpc/core.mjs +6 -6
  30. package/dist/jsonRpc/core.mjs.map +1 -1
  31. package/dist/jsonRpc/index.d.mts +4 -4
  32. package/dist/jsonRpc/index.mjs +2 -2
  33. package/dist/jsonRpc/types/generated.d.mts +14 -14
  34. package/dist/jsonRpc/types/generated.d.mts.map +1 -1
  35. package/dist/jsonRpc/types/index.d.mts +2 -2
  36. package/dist/jsonRpc/types/params.d.mts +8 -8
  37. package/dist/jsonRpc/types/params.d.mts.map +1 -1
  38. package/dist/multisig/publickey.d.mts +1 -1
  39. package/dist/multisig/publickey.mjs +1 -1
  40. package/dist/multisig/publickey.mjs.map +1 -1
  41. package/dist/multisig/signer.mjs +2 -2
  42. package/dist/multisig/signer.mjs.map +1 -1
  43. package/dist/transactions/Commands.mjs +3 -3
  44. package/dist/transactions/Commands.mjs.map +1 -1
  45. package/dist/transactions/Transaction.d.mts +6 -6
  46. package/dist/transactions/data/internal.d.mts +109 -109
  47. package/dist/transactions/data/v1.d.mts +220 -220
  48. package/dist/transactions/data/v1.d.mts.map +1 -1
  49. package/dist/transactions/data/v2.d.mts +16 -16
  50. package/dist/transactions/data/v2.d.mts.map +1 -1
  51. package/dist/transactions/executor/caching.mjs +1 -1
  52. package/dist/transactions/executor/caching.mjs.map +1 -1
  53. package/dist/transactions/executor/parallel.mjs +3 -3
  54. package/dist/transactions/executor/parallel.mjs.map +1 -1
  55. package/dist/transactions/executor/serial.mjs +1 -1
  56. package/dist/transactions/executor/serial.mjs.map +1 -1
  57. package/dist/utils/haneul-types.d.mts +2 -2
  58. package/dist/utils/haneul-types.d.mts.map +1 -1
  59. package/dist/utils/haneul-types.mjs +2 -2
  60. package/dist/utils/haneul-types.mjs.map +1 -1
  61. package/dist/utils/index.d.mts +2 -2
  62. package/dist/utils/index.mjs +2 -2
  63. package/dist/verify/verify.mjs +1 -1
  64. package/dist/verify/verify.mjs.map +1 -1
  65. package/dist/version.mjs +1 -1
  66. package/dist/version.mjs.map +1 -1
  67. package/dist/zklogin/bcs.d.mts +14 -14
  68. package/dist/zklogin/bcs.d.mts.map +1 -1
  69. package/dist/zklogin/publickey.d.mts +1 -1
  70. package/dist/zklogin/publickey.d.mts.map +1 -1
  71. package/dist/zklogin/publickey.mjs +9 -9
  72. package/dist/zklogin/publickey.mjs.map +1 -1
  73. package/package.json +199 -199
  74. package/src/bcs/bcs.ts +1 -1
  75. package/src/client/core-resolver.ts +2 -2
  76. package/src/client/core.ts +1 -1
  77. package/src/cryptography/keypair.ts +3 -3
  78. package/src/cryptography/publickey.ts +2 -2
  79. package/src/grpc/proto/haneul/rpc/v2/system_state.ts +3 -3
  80. package/src/jsonRpc/client.ts +57 -57
  81. package/src/jsonRpc/core.ts +7 -7
  82. package/src/jsonRpc/index.ts +1 -1
  83. package/src/jsonRpc/types/generated.ts +13 -13
  84. package/src/jsonRpc/types/params.ts +7 -7
  85. package/src/multisig/publickey.ts +1 -1
  86. package/src/multisig/signer.ts +2 -2
  87. package/src/transactions/Commands.ts +3 -3
  88. package/src/transactions/executor/caching.ts +1 -1
  89. package/src/transactions/executor/parallel.ts +3 -3
  90. package/src/transactions/executor/serial.ts +1 -1
  91. package/src/utils/haneul-types.ts +1 -1
  92. package/src/utils/index.ts +1 -1
  93. package/src/verify/verify.ts +1 -1
  94. package/src/version.ts +1 -1
  95. package/src/zklogin/publickey.ts +9 -9
@@ -1 +1 @@
1
- {"version":3,"file":"caching.mjs","names":["#client","bcs","#lastDigest"],"sources":["../../../src/transactions/executor/caching.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '../../bcs/index.js';\nimport type { ClientWithCoreApi } from '../../client/core.js';\nimport { coreClientResolveTransactionPlugin } from '../../client/core-resolver.js';\nimport type { HaneulClientTypes } from '../../client/types.js';\nimport type { Signer } from '../../cryptography/keypair.js';\nimport type { BuildTransactionOptions } from '../resolve.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { ObjectCache } from '../ObjectCache.js';\nimport type { Transaction } from '../Transaction.js';\nimport { isTransaction } from '../Transaction.js';\n\nexport interface ExecuteTransactionOptions<Include extends HaneulClientTypes.TransactionInclude = {}> {\n\ttransaction: Transaction | Uint8Array;\n\tsignatures: string[];\n\tinclude?: Include;\n}\n\nexport class CachingTransactionExecutor {\n\t#client: ClientWithCoreApi;\n\t#lastDigest: string | null = null;\n\tcache: ObjectCache;\n\n\tconstructor({\n\t\tclient,\n\t\t...options\n\t}: ObjectCacheOptions & {\n\t\tclient: ClientWithCoreApi;\n\t}) {\n\t\tthis.#client = client;\n\t\tthis.cache = new ObjectCache(options);\n\t}\n\n\t/**\n\t * Clears all Owned objects\n\t * Immutable objects, Shared objects, and Move function definitions will be preserved\n\t */\n\tasync reset() {\n\t\tawait Promise.all([\n\t\t\tthis.cache.clearOwnedObjects(),\n\t\t\tthis.cache.clearCustom(),\n\t\t\tthis.waitForLastTransaction(),\n\t\t]);\n\t}\n\n\tasync buildTransaction({\n\t\ttransaction,\n\t\t...options\n\t}: { transaction: Transaction } & BuildTransactionOptions) {\n\t\ttransaction.addBuildPlugin(this.cache.asPlugin());\n\t\ttransaction.addBuildPlugin(coreClientResolveTransactionPlugin);\n\t\treturn transaction.build({\n\t\t\tclient: this.#client,\n\t\t\t...options,\n\t\t});\n\t}\n\n\tasync executeTransaction<Include extends HaneulClientTypes.TransactionInclude = {}>({\n\t\ttransaction,\n\t\tsignatures,\n\t\tinclude,\n\t}: ExecuteTransactionOptions<Include>): Promise<\n\t\tHaneulClientTypes.TransactionResult<Include & { effects: true }>\n\t> {\n\t\tconst bytes = isTransaction(transaction)\n\t\t\t? await this.buildTransaction({ transaction })\n\t\t\t: transaction;\n\n\t\tconst results = await this.#client.core.executeTransaction({\n\t\t\ttransaction: bytes,\n\t\t\tsignatures,\n\t\t\tinclude: {\n\t\t\t\t...include,\n\t\t\t\teffects: true,\n\t\t\t},\n\t\t});\n\n\t\tconst tx = results.$kind === 'Transaction' ? results.Transaction : results.FailedTransaction;\n\t\tif (tx.effects?.bcs) {\n\t\t\tconst effects = bcs.TransactionEffects.parse(tx.effects.bcs);\n\t\t\tawait this.applyEffects(effects);\n\t\t}\n\n\t\treturn results as HaneulClientTypes.TransactionResult<Include & { effects: true }>;\n\t}\n\n\tasync signAndExecuteTransaction<Include extends HaneulClientTypes.TransactionInclude = {}>({\n\t\tinclude,\n\t\ttransaction,\n\t\tsigner,\n\t}: {\n\t\ttransaction: Transaction;\n\t\tsigner: Signer;\n\t\tinclude?: Include;\n\t}): Promise<HaneulClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\ttransaction.setSenderIfNotSet(signer.toSuiAddress());\n\t\tconst bytes = await this.buildTransaction({ transaction });\n\t\tconst { signature } = await signer.signTransaction(bytes);\n\t\treturn this.executeTransaction({\n\t\t\ttransaction: bytes,\n\t\t\tsignatures: [signature],\n\t\t\tinclude,\n\t\t});\n\t}\n\n\tasync applyEffects(effects: typeof bcs.TransactionEffects.$inferType) {\n\t\tthis.#lastDigest = effects.V2?.transactionDigest ?? null;\n\t\tawait this.cache.applyEffects(effects);\n\t}\n\n\tasync waitForLastTransaction() {\n\t\tif (this.#lastDigest) {\n\t\t\tawait this.#client.core.waitForTransaction({ digest: this.#lastDigest });\n\t\t\tthis.#lastDigest = null;\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;AAoBA,IAAa,6BAAb,MAAwC;CACvC;CACA,cAA6B;CAG7B,YAAY,EACX,QACA,GAAG,WAGD;AACF,QAAKA,SAAU;AACf,OAAK,QAAQ,IAAI,YAAY,QAAQ;;;;;;CAOtC,MAAM,QAAQ;AACb,QAAM,QAAQ,IAAI;GACjB,KAAK,MAAM,mBAAmB;GAC9B,KAAK,MAAM,aAAa;GACxB,KAAK,wBAAwB;GAC7B,CAAC;;CAGH,MAAM,iBAAiB,EACtB,aACA,GAAG,WACuD;AAC1D,cAAY,eAAe,KAAK,MAAM,UAAU,CAAC;AACjD,cAAY,eAAe,mCAAmC;AAC9D,SAAO,YAAY,MAAM;GACxB,QAAQ,MAAKA;GACb,GAAG;GACH,CAAC;;CAGH,MAAM,mBAA8E,EACnF,aACA,YACA,WAGC;EACD,MAAM,QAAQ,cAAc,YAAY,GACrC,MAAM,KAAK,iBAAiB,EAAE,aAAa,CAAC,GAC5C;EAEH,MAAM,UAAU,MAAM,MAAKA,OAAQ,KAAK,mBAAmB;GAC1D,aAAa;GACb;GACA,SAAS;IACR,GAAG;IACH,SAAS;IACT;GACD,CAAC;EAEF,MAAM,KAAK,QAAQ,UAAU,gBAAgB,QAAQ,cAAc,QAAQ;AAC3E,MAAI,GAAG,SAAS,KAAK;GACpB,MAAM,UAAUC,OAAI,mBAAmB,MAAM,GAAG,QAAQ,IAAI;AAC5D,SAAM,KAAK,aAAa,QAAQ;;AAGjC,SAAO;;CAGR,MAAM,0BAAqF,EAC1F,SACA,aACA,UAK6E;AAC7E,cAAY,kBAAkB,OAAO,cAAc,CAAC;EACpD,MAAM,QAAQ,MAAM,KAAK,iBAAiB,EAAE,aAAa,CAAC;EAC1D,MAAM,EAAE,cAAc,MAAM,OAAO,gBAAgB,MAAM;AACzD,SAAO,KAAK,mBAAmB;GAC9B,aAAa;GACb,YAAY,CAAC,UAAU;GACvB;GACA,CAAC;;CAGH,MAAM,aAAa,SAAmD;AACrE,QAAKC,aAAc,QAAQ,IAAI,qBAAqB;AACpD,QAAM,KAAK,MAAM,aAAa,QAAQ;;CAGvC,MAAM,yBAAyB;AAC9B,MAAI,MAAKA,YAAa;AACrB,SAAM,MAAKF,OAAQ,KAAK,mBAAmB,EAAE,QAAQ,MAAKE,YAAa,CAAC;AACxE,SAAKA,aAAc"}
1
+ {"version":3,"file":"caching.mjs","names":["#client","bcs","#lastDigest"],"sources":["../../../src/transactions/executor/caching.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '../../bcs/index.js';\nimport type { ClientWithCoreApi } from '../../client/core.js';\nimport { coreClientResolveTransactionPlugin } from '../../client/core-resolver.js';\nimport type { HaneulClientTypes } from '../../client/types.js';\nimport type { Signer } from '../../cryptography/keypair.js';\nimport type { BuildTransactionOptions } from '../resolve.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { ObjectCache } from '../ObjectCache.js';\nimport type { Transaction } from '../Transaction.js';\nimport { isTransaction } from '../Transaction.js';\n\nexport interface ExecuteTransactionOptions<Include extends HaneulClientTypes.TransactionInclude = {}> {\n\ttransaction: Transaction | Uint8Array;\n\tsignatures: string[];\n\tinclude?: Include;\n}\n\nexport class CachingTransactionExecutor {\n\t#client: ClientWithCoreApi;\n\t#lastDigest: string | null = null;\n\tcache: ObjectCache;\n\n\tconstructor({\n\t\tclient,\n\t\t...options\n\t}: ObjectCacheOptions & {\n\t\tclient: ClientWithCoreApi;\n\t}) {\n\t\tthis.#client = client;\n\t\tthis.cache = new ObjectCache(options);\n\t}\n\n\t/**\n\t * Clears all Owned objects\n\t * Immutable objects, Shared objects, and Move function definitions will be preserved\n\t */\n\tasync reset() {\n\t\tawait Promise.all([\n\t\t\tthis.cache.clearOwnedObjects(),\n\t\t\tthis.cache.clearCustom(),\n\t\t\tthis.waitForLastTransaction(),\n\t\t]);\n\t}\n\n\tasync buildTransaction({\n\t\ttransaction,\n\t\t...options\n\t}: { transaction: Transaction } & BuildTransactionOptions) {\n\t\ttransaction.addBuildPlugin(this.cache.asPlugin());\n\t\ttransaction.addBuildPlugin(coreClientResolveTransactionPlugin);\n\t\treturn transaction.build({\n\t\t\tclient: this.#client,\n\t\t\t...options,\n\t\t});\n\t}\n\n\tasync executeTransaction<Include extends HaneulClientTypes.TransactionInclude = {}>({\n\t\ttransaction,\n\t\tsignatures,\n\t\tinclude,\n\t}: ExecuteTransactionOptions<Include>): Promise<\n\t\tHaneulClientTypes.TransactionResult<Include & { effects: true }>\n\t> {\n\t\tconst bytes = isTransaction(transaction)\n\t\t\t? await this.buildTransaction({ transaction })\n\t\t\t: transaction;\n\n\t\tconst results = await this.#client.core.executeTransaction({\n\t\t\ttransaction: bytes,\n\t\t\tsignatures,\n\t\t\tinclude: {\n\t\t\t\t...include,\n\t\t\t\teffects: true,\n\t\t\t},\n\t\t});\n\n\t\tconst tx = results.$kind === 'Transaction' ? results.Transaction : results.FailedTransaction;\n\t\tif (tx.effects?.bcs) {\n\t\t\tconst effects = bcs.TransactionEffects.parse(tx.effects.bcs);\n\t\t\tawait this.applyEffects(effects);\n\t\t}\n\n\t\treturn results as HaneulClientTypes.TransactionResult<Include & { effects: true }>;\n\t}\n\n\tasync signAndExecuteTransaction<Include extends HaneulClientTypes.TransactionInclude = {}>({\n\t\tinclude,\n\t\ttransaction,\n\t\tsigner,\n\t}: {\n\t\ttransaction: Transaction;\n\t\tsigner: Signer;\n\t\tinclude?: Include;\n\t}): Promise<HaneulClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\ttransaction.setSenderIfNotSet(signer.toHaneulAddress());\n\t\tconst bytes = await this.buildTransaction({ transaction });\n\t\tconst { signature } = await signer.signTransaction(bytes);\n\t\treturn this.executeTransaction({\n\t\t\ttransaction: bytes,\n\t\t\tsignatures: [signature],\n\t\t\tinclude,\n\t\t});\n\t}\n\n\tasync applyEffects(effects: typeof bcs.TransactionEffects.$inferType) {\n\t\tthis.#lastDigest = effects.V2?.transactionDigest ?? null;\n\t\tawait this.cache.applyEffects(effects);\n\t}\n\n\tasync waitForLastTransaction() {\n\t\tif (this.#lastDigest) {\n\t\t\tawait this.#client.core.waitForTransaction({ digest: this.#lastDigest });\n\t\t\tthis.#lastDigest = null;\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;AAoBA,IAAa,6BAAb,MAAwC;CACvC;CACA,cAA6B;CAG7B,YAAY,EACX,QACA,GAAG,WAGD;AACF,QAAKA,SAAU;AACf,OAAK,QAAQ,IAAI,YAAY,QAAQ;;;;;;CAOtC,MAAM,QAAQ;AACb,QAAM,QAAQ,IAAI;GACjB,KAAK,MAAM,mBAAmB;GAC9B,KAAK,MAAM,aAAa;GACxB,KAAK,wBAAwB;GAC7B,CAAC;;CAGH,MAAM,iBAAiB,EACtB,aACA,GAAG,WACuD;AAC1D,cAAY,eAAe,KAAK,MAAM,UAAU,CAAC;AACjD,cAAY,eAAe,mCAAmC;AAC9D,SAAO,YAAY,MAAM;GACxB,QAAQ,MAAKA;GACb,GAAG;GACH,CAAC;;CAGH,MAAM,mBAA8E,EACnF,aACA,YACA,WAGC;EACD,MAAM,QAAQ,cAAc,YAAY,GACrC,MAAM,KAAK,iBAAiB,EAAE,aAAa,CAAC,GAC5C;EAEH,MAAM,UAAU,MAAM,MAAKA,OAAQ,KAAK,mBAAmB;GAC1D,aAAa;GACb;GACA,SAAS;IACR,GAAG;IACH,SAAS;IACT;GACD,CAAC;EAEF,MAAM,KAAK,QAAQ,UAAU,gBAAgB,QAAQ,cAAc,QAAQ;AAC3E,MAAI,GAAG,SAAS,KAAK;GACpB,MAAM,UAAUC,OAAI,mBAAmB,MAAM,GAAG,QAAQ,IAAI;AAC5D,SAAM,KAAK,aAAa,QAAQ;;AAGjC,SAAO;;CAGR,MAAM,0BAAqF,EAC1F,SACA,aACA,UAK6E;AAC7E,cAAY,kBAAkB,OAAO,iBAAiB,CAAC;EACvD,MAAM,QAAQ,MAAM,KAAK,iBAAiB,EAAE,aAAa,CAAC;EAC1D,MAAM,EAAE,cAAc,MAAM,OAAO,gBAAgB,MAAM;AACzD,SAAO,KAAK,mBAAmB;GAC9B,aAAa;GACb,YAAY,CAAC,UAAU;GACvB;GACA,CAAC;;CAGH,MAAM,aAAa,SAAmD;AACrE,QAAKC,aAAc,QAAQ,IAAI,qBAAqB;AACpD,QAAM,KAAK,MAAM,aAAa,QAAQ;;CAGvC,MAAM,yBAAyB;AAC9B,MAAI,MAAKA,YAAa;AACrB,SAAM,MAAKF,OAAQ,KAAK,mBAAmB,EAAE,QAAQ,MAAKE,YAAa,CAAC;AACxE,SAAKA,aAAc"}
@@ -104,7 +104,7 @@ var ParallelTransactionExecutor = class {
104
104
  async #execute(transaction, usedObjects, include, additionalSignatures = []) {
105
105
  let gasCoin = null;
106
106
  try {
107
- transaction.setSenderIfNotSet(this.#signer.toSuiAddress());
107
+ transaction.setSenderIfNotSet(this.#signer.toHaneulAddress());
108
108
  await this.#buildQueue.runTask(async () => {
109
109
  if (!transaction.getData().gasData.price) transaction.setGasPrice(await this.#getGasPrice());
110
110
  transaction.setGasBudgetIfNotSet(this.#defaultGasBudget);
@@ -139,7 +139,7 @@ var ParallelTransactionExecutor = class {
139
139
  const gasUsed = effects.gasUsed;
140
140
  if (gasCoin && gasUsed && gasObject) {
141
141
  const coin = gasCoin;
142
- if ((gasObject.outputOwner?.AddressOwner ?? gasObject.outputOwner?.ObjectOwner) === this.#signer.toSuiAddress()) {
142
+ if ((gasObject.outputOwner?.AddressOwner ?? gasObject.outputOwner?.ObjectOwner) === this.#signer.toHaneulAddress()) {
143
143
  const totalUsed = BigInt(gasUsed.computationCost) + BigInt(gasUsed.storageCost) + BigInt(gasUsed.storageCost) - BigInt(gasUsed.storageRebate);
144
144
  const remainingBalance = coin.balance - totalUsed;
145
145
  let usesGasCoin = false;
@@ -245,7 +245,7 @@ var ParallelTransactionExecutor = class {
245
245
  const batchSize = Math.min(this.#coinBatchSize, this.#maxPoolSize - (this.#coinPool.length + this.#pendingTransactions) + 1);
246
246
  if (batchSize === 0) return;
247
247
  const txb = new Transaction();
248
- const address = this.#signer.toSuiAddress();
248
+ const address = this.#signer.toHaneulAddress();
249
249
  txb.setSender(address);
250
250
  if (this.#sourceCoins) {
251
251
  const refs = [];
@@ -1 +1 @@
1
- {"version":3,"file":"parallel.mjs","names":["#signer","#client","#gasMode","#coinBatchSize","#initialCoinBalance","#minimumCoinBalance","#sourceCoins","#defaultGasBudget","#maxPoolSize","#cache","#executeQueue","#epochInfo","#updateCache","#waitForLastDigest","#getUsedObjects","#execute","#objectIdQueues","#buildQueue","#getGasPrice","#pendingTransactions","#getValidDuringExpiration","#getGasCoin","#coinPool","#lastDigest","#cacheLock","#refillCoinPool","#ensureEpochInfo","#epochInfoPromise","#fetchEpochInfo"],"sources":["../../../src/transactions/executor/parallel.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { promiseWithResolvers } from '@haneullabs/utils';\nimport type { HaneulObjectRef } from '../../bcs/types.js';\nimport type { ClientWithCoreApi } from '../../client/core.js';\nimport { coreClientResolveTransactionPlugin } from '../../client/core-resolver.js';\nimport type { HaneulClientTypes } from '../../client/types.js';\nimport type { Signer } from '../../cryptography/index.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { Transaction } from '../Transaction.js';\nimport { TransactionDataBuilder } from '../TransactionData.js';\nimport { CachingTransactionExecutor } from './caching.js';\nimport { ParallelQueue, SerialQueue } from './queue.js';\n\nconst PARALLEL_EXECUTOR_DEFAULTS = {\n\tcoinBatchSize: 20,\n\tinitialCoinBalance: 200_000_000n,\n\tminimumCoinBalance: 50_000_000n,\n\tmaxPoolSize: 50,\n} satisfies Partial<ParallelTransactionExecutorCoinOptions>;\n\nconst EPOCH_BOUNDARY_WINDOW = 60_000;\n\ninterface ParallelTransactionExecutorBaseOptions extends Omit<ObjectCacheOptions, 'address'> {\n\tclient: ClientWithCoreApi;\n\tsigner: Signer;\n\t/** The gasBudget to use if the transaction has not defined it's own gasBudget, defaults to `minimumCoinBalance` */\n\tdefaultGasBudget?: bigint;\n\t/** The maximum number of transactions that can be execute in parallel, this also determines the maximum number of gas coins that will be created */\n\tmaxPoolSize?: number;\n}\n\nexport interface ParallelTransactionExecutorCoinOptions extends ParallelTransactionExecutorBaseOptions {\n\t/** Gas mode - use owned coins for gas payments (default) */\n\tgasMode?: 'coins';\n\t/** The number of coins to create in a batch when refilling the gas pool */\n\tcoinBatchSize?: number;\n\t/** The initial balance of each coin created for the gas pool */\n\tinitialCoinBalance?: bigint;\n\t/** The minimum balance of a coin that can be reused for future transactions. If the gasCoin is below this value, it will be used when refilling the gasPool */\n\tminimumCoinBalance?: bigint;\n\t/** An initial list of coins used to fund the gas pool, uses all owned HANEUL coins by default */\n\tsourceCoins?: string[];\n}\n\nexport interface ParallelTransactionExecutorAddressBalanceOptions extends ParallelTransactionExecutorBaseOptions {\n\t/** Gas mode - use address balance for gas payments instead of owned coins */\n\tgasMode: 'addressBalance';\n}\n\n/** Options for ParallelTransactionExecutor - discriminated union based on gasMode */\nexport type ParallelTransactionExecutorOptions =\n\t| ParallelTransactionExecutorCoinOptions\n\t| ParallelTransactionExecutorAddressBalanceOptions;\n\ninterface CoinWithBalance {\n\tid: string;\n\tversion: string;\n\tdigest: string;\n\tbalance: bigint;\n}\nexport class ParallelTransactionExecutor {\n\t#signer: Signer;\n\t#client: ClientWithCoreApi;\n\t#gasMode: 'coins' | 'addressBalance';\n\t#coinBatchSize: number;\n\t#initialCoinBalance: bigint;\n\t#minimumCoinBalance: bigint;\n\t#defaultGasBudget: bigint;\n\t#maxPoolSize: number;\n\t#sourceCoins: Map<string, HaneulObjectRef | null> | null;\n\t#coinPool: CoinWithBalance[] = [];\n\t#cache: CachingTransactionExecutor;\n\t#objectIdQueues = new Map<string, (() => void)[]>();\n\t#buildQueue = new SerialQueue();\n\t#executeQueue: ParallelQueue;\n\t#lastDigest: string | null = null;\n\t#cacheLock: Promise<void> | null = null;\n\t#pendingTransactions = 0;\n\t#epochInfo: null | {\n\t\tepoch: string;\n\t\tprice: bigint;\n\t\texpiration: number;\n\t\tchainIdentifier: string;\n\t} = null;\n\t#epochInfoPromise: Promise<void> | null = null;\n\n\tconstructor(options: ParallelTransactionExecutorOptions) {\n\t\tthis.#signer = options.signer;\n\t\tthis.#client = options.client;\n\t\tthis.#gasMode = options.gasMode ?? 'coins';\n\n\t\tif (this.#gasMode === 'coins') {\n\t\t\tconst coinOptions = options as ParallelTransactionExecutorCoinOptions;\n\t\t\tthis.#coinBatchSize = coinOptions.coinBatchSize ?? PARALLEL_EXECUTOR_DEFAULTS.coinBatchSize;\n\t\t\tthis.#initialCoinBalance =\n\t\t\t\tcoinOptions.initialCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.initialCoinBalance;\n\t\t\tthis.#minimumCoinBalance =\n\t\t\t\tcoinOptions.minimumCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance;\n\t\t\tthis.#sourceCoins = coinOptions.sourceCoins\n\t\t\t\t? new Map(coinOptions.sourceCoins.map((id) => [id, null]))\n\t\t\t\t: null;\n\t\t} else {\n\t\t\tthis.#coinBatchSize = 0;\n\t\t\tthis.#initialCoinBalance = 0n;\n\t\t\tthis.#minimumCoinBalance = PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance;\n\t\t\tthis.#sourceCoins = null;\n\t\t}\n\n\t\tthis.#defaultGasBudget = options.defaultGasBudget ?? this.#minimumCoinBalance;\n\t\tthis.#maxPoolSize = options.maxPoolSize ?? PARALLEL_EXECUTOR_DEFAULTS.maxPoolSize;\n\t\tthis.#cache = new CachingTransactionExecutor({\n\t\t\tclient: options.client,\n\t\t\tcache: options.cache,\n\t\t});\n\t\tthis.#executeQueue = new ParallelQueue(this.#maxPoolSize);\n\t}\n\n\tresetCache() {\n\t\tthis.#epochInfo = null;\n\t\treturn this.#updateCache(() => this.#cache.reset());\n\t}\n\n\tasync waitForLastTransaction() {\n\t\tawait this.#updateCache(() => this.#waitForLastDigest());\n\t}\n\n\tasync executeTransaction<Include extends HaneulClientTypes.TransactionInclude = {}>(\n\t\ttransaction: Transaction,\n\t\tinclude?: Include,\n\t\tadditionalSignatures: string[] = [],\n\t): Promise<HaneulClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\tconst { promise, resolve, reject } =\n\t\t\tpromiseWithResolvers<HaneulClientTypes.TransactionResult<Include & { effects: true }>>();\n\t\tconst usedObjects = await this.#getUsedObjects(transaction);\n\n\t\tconst execute = () => {\n\t\t\tthis.#executeQueue.runTask(() => {\n\t\t\t\tconst promise = this.#execute(transaction, usedObjects, include, additionalSignatures);\n\n\t\t\t\treturn promise.then(resolve, reject);\n\t\t\t});\n\t\t};\n\n\t\tconst conflicts = new Set<string>();\n\n\t\tusedObjects.forEach((objectId) => {\n\t\t\tconst queue = this.#objectIdQueues.get(objectId);\n\t\t\tif (queue) {\n\t\t\t\tconflicts.add(objectId);\n\t\t\t\tthis.#objectIdQueues.get(objectId)!.push(() => {\n\t\t\t\t\tconflicts.delete(objectId);\n\t\t\t\t\tif (conflicts.size === 0) {\n\t\t\t\t\t\texecute();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthis.#objectIdQueues.set(objectId, []);\n\t\t\t}\n\t\t});\n\n\t\tif (conflicts.size === 0) {\n\t\t\texecute();\n\t\t}\n\n\t\treturn promise;\n\t}\n\n\tasync #getUsedObjects(transaction: Transaction) {\n\t\tconst usedObjects = new Set<string>();\n\t\tlet serialized = false;\n\n\t\ttransaction.addSerializationPlugin(async (blockData, _options, next) => {\n\t\t\tawait next();\n\n\t\t\tif (serialized) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tserialized = true;\n\n\t\t\tblockData.inputs.forEach((input) => {\n\t\t\t\tif (input.Object?.ImmOrOwnedObject?.objectId) {\n\t\t\t\t\tusedObjects.add(input.Object.ImmOrOwnedObject.objectId);\n\t\t\t\t} else if (input.Object?.Receiving?.objectId) {\n\t\t\t\t\tusedObjects.add(input.Object.Receiving.objectId);\n\t\t\t\t} else if (\n\t\t\t\t\tinput.UnresolvedObject?.objectId &&\n\t\t\t\t\t!input.UnresolvedObject.initialSharedVersion\n\t\t\t\t) {\n\t\t\t\t\tusedObjects.add(input.UnresolvedObject.objectId);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\tawait transaction.prepareForSerialization({ client: this.#client });\n\n\t\treturn usedObjects;\n\t}\n\n\tasync #execute<Include extends HaneulClientTypes.TransactionInclude = {}>(\n\t\ttransaction: Transaction,\n\t\tusedObjects: Set<string>,\n\t\tinclude?: Include,\n\t\tadditionalSignatures: string[] = [],\n\t): Promise<HaneulClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\tlet gasCoin: CoinWithBalance | null = null;\n\t\ttry {\n\t\t\ttransaction.setSenderIfNotSet(this.#signer.toSuiAddress());\n\n\t\t\tawait this.#buildQueue.runTask(async () => {\n\t\t\t\tconst data = transaction.getData();\n\n\t\t\t\tif (!data.gasData.price) {\n\t\t\t\t\ttransaction.setGasPrice(await this.#getGasPrice());\n\t\t\t\t}\n\n\t\t\t\ttransaction.setGasBudgetIfNotSet(this.#defaultGasBudget);\n\n\t\t\t\tawait this.#updateCache();\n\t\t\t\tthis.#pendingTransactions++;\n\n\t\t\t\tif (this.#gasMode === 'addressBalance') {\n\t\t\t\t\t// Address balance mode: use empty gas payment with ValidDuring expiration\n\t\t\t\t\ttransaction.setGasPayment([]);\n\t\t\t\t\ttransaction.setExpiration(await this.#getValidDuringExpiration());\n\t\t\t\t} else {\n\t\t\t\t\t// Coin mode: use gas coin from pool\n\t\t\t\t\tgasCoin = await this.#getGasCoin();\n\t\t\t\t\ttransaction.setGasPayment([\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tobjectId: gasCoin.id,\n\t\t\t\t\t\t\tversion: gasCoin.version,\n\t\t\t\t\t\t\tdigest: gasCoin.digest,\n\t\t\t\t\t\t},\n\t\t\t\t\t]);\n\t\t\t\t}\n\n\t\t\t\t// Resolve cached references\n\t\t\t\tawait this.#cache.buildTransaction({ transaction, onlyTransactionKind: true });\n\t\t\t});\n\n\t\t\tconst bytes = await transaction.build({ client: this.#client });\n\n\t\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\n\t\t\tconst results = await this.#cache.executeTransaction({\n\t\t\t\ttransaction: bytes,\n\t\t\t\tsignatures: [signature, ...additionalSignatures],\n\t\t\t\tinclude,\n\t\t\t});\n\n\t\t\tconst tx = results.$kind === 'Transaction' ? results.Transaction : results.FailedTransaction;\n\t\t\tconst effects = tx.effects!;\n\t\t\tconst gasObject = effects.gasObject;\n\t\t\tconst gasUsed = effects.gasUsed;\n\n\t\t\tif (gasCoin && gasUsed && gasObject) {\n\t\t\t\tconst coin = gasCoin as CoinWithBalance;\n\t\t\t\tconst gasOwner = gasObject.outputOwner?.AddressOwner ?? gasObject.outputOwner?.ObjectOwner;\n\n\t\t\t\tif (gasOwner === this.#signer.toSuiAddress()) {\n\t\t\t\t\tconst totalUsed =\n\t\t\t\t\t\tBigInt(gasUsed.computationCost) +\n\t\t\t\t\t\tBigInt(gasUsed.storageCost) +\n\t\t\t\t\t\tBigInt(gasUsed.storageCost) -\n\t\t\t\t\t\tBigInt(gasUsed.storageRebate);\n\t\t\t\t\tconst remainingBalance = coin.balance - totalUsed;\n\n\t\t\t\t\tlet usesGasCoin = false;\n\t\t\t\t\tnew TransactionDataBuilder(transaction.getData()).mapArguments((arg) => {\n\t\t\t\t\t\tif (arg.$kind === 'GasCoin') {\n\t\t\t\t\t\t\tusesGasCoin = true;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn arg;\n\t\t\t\t\t});\n\n\t\t\t\t\tconst gasRef = {\n\t\t\t\t\t\tobjectId: gasObject.objectId,\n\t\t\t\t\t\tversion: gasObject.outputVersion!,\n\t\t\t\t\t\tdigest: gasObject.outputDigest!,\n\t\t\t\t\t};\n\n\t\t\t\t\tif (!usesGasCoin && remainingBalance >= this.#minimumCoinBalance) {\n\t\t\t\t\t\tthis.#coinPool.push({\n\t\t\t\t\t\t\tid: gasRef.objectId,\n\t\t\t\t\t\t\tversion: gasRef.version,\n\t\t\t\t\t\t\tdigest: gasRef.digest,\n\t\t\t\t\t\t\tbalance: remainingBalance,\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (!this.#sourceCoins) {\n\t\t\t\t\t\t\tthis.#sourceCoins = new Map();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.#sourceCoins.set(gasRef.objectId, gasRef);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.#lastDigest = tx.digest;\n\n\t\t\treturn results as HaneulClientTypes.TransactionResult<Include & { effects: true }>;\n\t\t} catch (error) {\n\t\t\tif (gasCoin) {\n\t\t\t\tif (!this.#sourceCoins) {\n\t\t\t\t\tthis.#sourceCoins = new Map();\n\t\t\t\t}\n\n\t\t\t\tthis.#sourceCoins.set((gasCoin as CoinWithBalance).id, null);\n\t\t\t}\n\n\t\t\tawait this.#updateCache(async () => {\n\t\t\t\tawait Promise.all([\n\t\t\t\t\tthis.#cache.cache.deleteObjects([...usedObjects]),\n\t\t\t\t\tthis.#waitForLastDigest(),\n\t\t\t\t]);\n\t\t\t});\n\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tusedObjects.forEach((objectId) => {\n\t\t\t\tconst queue = this.#objectIdQueues.get(objectId);\n\t\t\t\tif (queue && queue.length > 0) {\n\t\t\t\t\tqueue.shift()!();\n\t\t\t\t} else if (queue) {\n\t\t\t\t\tthis.#objectIdQueues.delete(objectId);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis.#pendingTransactions--;\n\t\t}\n\t}\n\n\t/** Helper for synchronizing cache updates, by ensuring only one update happens at a time. This can also be used to wait for any pending cache updates */\n\tasync #updateCache(fn?: () => Promise<void>) {\n\t\tif (this.#cacheLock) {\n\t\t\tawait this.#cacheLock;\n\t\t}\n\n\t\tthis.#cacheLock =\n\t\t\tfn?.().then(\n\t\t\t\t() => {\n\t\t\t\t\tthis.#cacheLock = null;\n\t\t\t\t},\n\t\t\t\t() => {},\n\t\t\t) ?? null;\n\t}\n\n\tasync #waitForLastDigest() {\n\t\tconst digest = this.#lastDigest;\n\t\tif (digest) {\n\t\t\tthis.#lastDigest = null;\n\t\t\tawait this.#client.core.waitForTransaction({ digest });\n\t\t}\n\t}\n\n\tasync #getGasCoin() {\n\t\tif (this.#coinPool.length === 0 && this.#pendingTransactions <= this.#maxPoolSize) {\n\t\t\tawait this.#refillCoinPool();\n\t\t}\n\n\t\tif (this.#coinPool.length === 0) {\n\t\t\tthrow new Error('No coins available');\n\t\t}\n\n\t\tconst coin = this.#coinPool.shift()!;\n\t\treturn coin;\n\t}\n\n\tasync #getGasPrice(): Promise<bigint> {\n\t\tawait this.#ensureEpochInfo();\n\t\treturn this.#epochInfo!.price;\n\t}\n\n\tasync #getValidDuringExpiration() {\n\t\tawait this.#ensureEpochInfo();\n\t\tconst currentEpoch = BigInt(this.#epochInfo!.epoch);\n\t\treturn {\n\t\t\tValidDuring: {\n\t\t\t\tminEpoch: String(currentEpoch),\n\t\t\t\tmaxEpoch: String(currentEpoch + 1n),\n\t\t\t\tminTimestamp: null,\n\t\t\t\tmaxTimestamp: null,\n\t\t\t\tchain: this.#epochInfo!.chainIdentifier,\n\t\t\t\tnonce: (Math.random() * 0x100000000) >>> 0,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync #ensureEpochInfo(): Promise<void> {\n\t\tif (this.#epochInfo && this.#epochInfo.expiration - EPOCH_BOUNDARY_WINDOW - Date.now() > 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.#epochInfoPromise) {\n\t\t\tawait this.#epochInfoPromise;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#epochInfoPromise = this.#fetchEpochInfo();\n\t\ttry {\n\t\t\tawait this.#epochInfoPromise;\n\t\t} finally {\n\t\t\tthis.#epochInfoPromise = null;\n\t\t}\n\t}\n\n\tasync #fetchEpochInfo(): Promise<void> {\n\t\tconst [{ systemState }, { chainIdentifier }] = await Promise.all([\n\t\t\tthis.#client.core.getCurrentSystemState(),\n\t\t\tthis.#client.core.getChainIdentifier(),\n\t\t]);\n\n\t\tthis.#epochInfo = {\n\t\t\tepoch: systemState.epoch,\n\t\t\tprice: BigInt(systemState.referenceGasPrice),\n\t\t\texpiration:\n\t\t\t\tNumber(systemState.epochStartTimestampMs) + Number(systemState.parameters.epochDurationMs),\n\t\t\tchainIdentifier,\n\t\t};\n\t}\n\n\tasync #refillCoinPool() {\n\t\tconst batchSize = Math.min(\n\t\t\tthis.#coinBatchSize,\n\t\t\tthis.#maxPoolSize - (this.#coinPool.length + this.#pendingTransactions) + 1,\n\t\t);\n\n\t\tif (batchSize === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst txb = new Transaction();\n\t\tconst address = this.#signer.toSuiAddress();\n\t\ttxb.setSender(address);\n\n\t\tif (this.#sourceCoins) {\n\t\t\tconst refs = [];\n\t\t\tconst ids = [];\n\t\t\tfor (const [id, ref] of this.#sourceCoins) {\n\t\t\t\tif (ref) {\n\t\t\t\t\trefs.push(ref);\n\t\t\t\t} else {\n\t\t\t\t\tids.push(id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (ids.length > 0) {\n\t\t\t\tconst { objects } = await this.#client.core.getObjects({\n\t\t\t\t\tobjectIds: ids,\n\t\t\t\t});\n\t\t\t\trefs.push(\n\t\t\t\t\t...objects\n\t\t\t\t\t\t.filter((obj): obj is HaneulClientTypes.Object => !(obj instanceof Error))\n\t\t\t\t\t\t.map((obj) => ({\n\t\t\t\t\t\t\tobjectId: obj.objectId,\n\t\t\t\t\t\t\tversion: obj.version,\n\t\t\t\t\t\t\tdigest: obj.digest,\n\t\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\ttxb.setGasPayment(refs);\n\t\t\tthis.#sourceCoins = new Map();\n\t\t}\n\n\t\tconst amounts = new Array(batchSize).fill(this.#initialCoinBalance);\n\t\tconst splitResults = txb.splitCoins(txb.gas, amounts);\n\t\tconst coinResults = [];\n\t\tfor (let i = 0; i < amounts.length; i++) {\n\t\t\tcoinResults.push(splitResults[i]);\n\t\t}\n\t\ttxb.transferObjects(coinResults, address);\n\n\t\tawait this.waitForLastTransaction();\n\n\t\ttxb.addBuildPlugin(coreClientResolveTransactionPlugin);\n\t\tconst bytes = await txb.build({ client: this.#client });\n\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\n\t\tconst result = await this.#client.core.executeTransaction({\n\t\t\ttransaction: bytes,\n\t\t\tsignatures: [signature],\n\t\t\tinclude: { effects: true },\n\t\t});\n\n\t\tconst tx = result.$kind === 'Transaction' ? result.Transaction : result.FailedTransaction;\n\t\tconst effects = tx.effects!;\n\n\t\teffects.changedObjects.forEach((changedObj) => {\n\t\t\tif (\n\t\t\t\tchangedObj.objectId === effects.gasObject?.objectId ||\n\t\t\t\tchangedObj.outputState !== 'ObjectWrite'\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.#coinPool.push({\n\t\t\t\tid: changedObj.objectId,\n\t\t\t\tversion: changedObj.outputVersion!,\n\t\t\t\tdigest: changedObj.outputDigest!,\n\t\t\t\tbalance: BigInt(this.#initialCoinBalance),\n\t\t\t});\n\t\t});\n\n\t\tif (!this.#sourceCoins) {\n\t\t\tthis.#sourceCoins = new Map();\n\t\t}\n\n\t\tconst gasObject = effects.gasObject!;\n\t\tthis.#sourceCoins!.set(gasObject.objectId, {\n\t\t\tobjectId: gasObject.objectId,\n\t\t\tversion: gasObject.outputVersion!,\n\t\t\tdigest: gasObject.outputDigest!,\n\t\t});\n\n\t\tawait this.#client.core.waitForTransaction({ digest: tx.digest });\n\t}\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,6BAA6B;CAClC,eAAe;CACf,oBAAoB;CACpB,oBAAoB;CACpB,aAAa;CACb;AAED,MAAM,wBAAwB;AAwC9B,IAAa,8BAAb,MAAyC;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,YAA+B,EAAE;CACjC;CACA,kCAAkB,IAAI,KAA6B;CACnD,cAAc,IAAI,aAAa;CAC/B;CACA,cAA6B;CAC7B,aAAmC;CACnC,uBAAuB;CACvB,aAKI;CACJ,oBAA0C;CAE1C,YAAY,SAA6C;AACxD,QAAKA,SAAU,QAAQ;AACvB,QAAKC,SAAU,QAAQ;AACvB,QAAKC,UAAW,QAAQ,WAAW;AAEnC,MAAI,MAAKA,YAAa,SAAS;GAC9B,MAAM,cAAc;AACpB,SAAKC,gBAAiB,YAAY,iBAAiB,2BAA2B;AAC9E,SAAKC,qBACJ,YAAY,sBAAsB,2BAA2B;AAC9D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["#signer","#client","#gasMode","#coinBatchSize","#initialCoinBalance","#minimumCoinBalance","#sourceCoins","#defaultGasBudget","#maxPoolSize","#cache","#executeQueue","#epochInfo","#updateCache","#waitForLastDigest","#getUsedObjects","#execute","#objectIdQueues","#buildQueue","#getGasPrice","#pendingTransactions","#getValidDuringExpiration","#getGasCoin","#coinPool","#lastDigest","#cacheLock","#refillCoinPool","#ensureEpochInfo","#epochInfoPromise","#fetchEpochInfo"],"sources":["../../../src/transactions/executor/parallel.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { promiseWithResolvers } from '@haneullabs/utils';\nimport type { HaneulObjectRef } from '../../bcs/types.js';\nimport type { ClientWithCoreApi } from '../../client/core.js';\nimport { coreClientResolveTransactionPlugin } from '../../client/core-resolver.js';\nimport type { HaneulClientTypes } from '../../client/types.js';\nimport type { Signer } from '../../cryptography/index.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { Transaction } from '../Transaction.js';\nimport { TransactionDataBuilder } from '../TransactionData.js';\nimport { CachingTransactionExecutor } from './caching.js';\nimport { ParallelQueue, SerialQueue } from './queue.js';\n\nconst PARALLEL_EXECUTOR_DEFAULTS = {\n\tcoinBatchSize: 20,\n\tinitialCoinBalance: 200_000_000n,\n\tminimumCoinBalance: 50_000_000n,\n\tmaxPoolSize: 50,\n} satisfies Partial<ParallelTransactionExecutorCoinOptions>;\n\nconst EPOCH_BOUNDARY_WINDOW = 60_000;\n\ninterface ParallelTransactionExecutorBaseOptions extends Omit<ObjectCacheOptions, 'address'> {\n\tclient: ClientWithCoreApi;\n\tsigner: Signer;\n\t/** The gasBudget to use if the transaction has not defined it's own gasBudget, defaults to `minimumCoinBalance` */\n\tdefaultGasBudget?: bigint;\n\t/** The maximum number of transactions that can be execute in parallel, this also determines the maximum number of gas coins that will be created */\n\tmaxPoolSize?: number;\n}\n\nexport interface ParallelTransactionExecutorCoinOptions extends ParallelTransactionExecutorBaseOptions {\n\t/** Gas mode - use owned coins for gas payments (default) */\n\tgasMode?: 'coins';\n\t/** The number of coins to create in a batch when refilling the gas pool */\n\tcoinBatchSize?: number;\n\t/** The initial balance of each coin created for the gas pool */\n\tinitialCoinBalance?: bigint;\n\t/** The minimum balance of a coin that can be reused for future transactions. If the gasCoin is below this value, it will be used when refilling the gasPool */\n\tminimumCoinBalance?: bigint;\n\t/** An initial list of coins used to fund the gas pool, uses all owned HANEUL coins by default */\n\tsourceCoins?: string[];\n}\n\nexport interface ParallelTransactionExecutorAddressBalanceOptions extends ParallelTransactionExecutorBaseOptions {\n\t/** Gas mode - use address balance for gas payments instead of owned coins */\n\tgasMode: 'addressBalance';\n}\n\n/** Options for ParallelTransactionExecutor - discriminated union based on gasMode */\nexport type ParallelTransactionExecutorOptions =\n\t| ParallelTransactionExecutorCoinOptions\n\t| ParallelTransactionExecutorAddressBalanceOptions;\n\ninterface CoinWithBalance {\n\tid: string;\n\tversion: string;\n\tdigest: string;\n\tbalance: bigint;\n}\nexport class ParallelTransactionExecutor {\n\t#signer: Signer;\n\t#client: ClientWithCoreApi;\n\t#gasMode: 'coins' | 'addressBalance';\n\t#coinBatchSize: number;\n\t#initialCoinBalance: bigint;\n\t#minimumCoinBalance: bigint;\n\t#defaultGasBudget: bigint;\n\t#maxPoolSize: number;\n\t#sourceCoins: Map<string, HaneulObjectRef | null> | null;\n\t#coinPool: CoinWithBalance[] = [];\n\t#cache: CachingTransactionExecutor;\n\t#objectIdQueues = new Map<string, (() => void)[]>();\n\t#buildQueue = new SerialQueue();\n\t#executeQueue: ParallelQueue;\n\t#lastDigest: string | null = null;\n\t#cacheLock: Promise<void> | null = null;\n\t#pendingTransactions = 0;\n\t#epochInfo: null | {\n\t\tepoch: string;\n\t\tprice: bigint;\n\t\texpiration: number;\n\t\tchainIdentifier: string;\n\t} = null;\n\t#epochInfoPromise: Promise<void> | null = null;\n\n\tconstructor(options: ParallelTransactionExecutorOptions) {\n\t\tthis.#signer = options.signer;\n\t\tthis.#client = options.client;\n\t\tthis.#gasMode = options.gasMode ?? 'coins';\n\n\t\tif (this.#gasMode === 'coins') {\n\t\t\tconst coinOptions = options as ParallelTransactionExecutorCoinOptions;\n\t\t\tthis.#coinBatchSize = coinOptions.coinBatchSize ?? PARALLEL_EXECUTOR_DEFAULTS.coinBatchSize;\n\t\t\tthis.#initialCoinBalance =\n\t\t\t\tcoinOptions.initialCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.initialCoinBalance;\n\t\t\tthis.#minimumCoinBalance =\n\t\t\t\tcoinOptions.minimumCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance;\n\t\t\tthis.#sourceCoins = coinOptions.sourceCoins\n\t\t\t\t? new Map(coinOptions.sourceCoins.map((id) => [id, null]))\n\t\t\t\t: null;\n\t\t} else {\n\t\t\tthis.#coinBatchSize = 0;\n\t\t\tthis.#initialCoinBalance = 0n;\n\t\t\tthis.#minimumCoinBalance = PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance;\n\t\t\tthis.#sourceCoins = null;\n\t\t}\n\n\t\tthis.#defaultGasBudget = options.defaultGasBudget ?? this.#minimumCoinBalance;\n\t\tthis.#maxPoolSize = options.maxPoolSize ?? PARALLEL_EXECUTOR_DEFAULTS.maxPoolSize;\n\t\tthis.#cache = new CachingTransactionExecutor({\n\t\t\tclient: options.client,\n\t\t\tcache: options.cache,\n\t\t});\n\t\tthis.#executeQueue = new ParallelQueue(this.#maxPoolSize);\n\t}\n\n\tresetCache() {\n\t\tthis.#epochInfo = null;\n\t\treturn this.#updateCache(() => this.#cache.reset());\n\t}\n\n\tasync waitForLastTransaction() {\n\t\tawait this.#updateCache(() => this.#waitForLastDigest());\n\t}\n\n\tasync executeTransaction<Include extends HaneulClientTypes.TransactionInclude = {}>(\n\t\ttransaction: Transaction,\n\t\tinclude?: Include,\n\t\tadditionalSignatures: string[] = [],\n\t): Promise<HaneulClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\tconst { promise, resolve, reject } =\n\t\t\tpromiseWithResolvers<HaneulClientTypes.TransactionResult<Include & { effects: true }>>();\n\t\tconst usedObjects = await this.#getUsedObjects(transaction);\n\n\t\tconst execute = () => {\n\t\t\tthis.#executeQueue.runTask(() => {\n\t\t\t\tconst promise = this.#execute(transaction, usedObjects, include, additionalSignatures);\n\n\t\t\t\treturn promise.then(resolve, reject);\n\t\t\t});\n\t\t};\n\n\t\tconst conflicts = new Set<string>();\n\n\t\tusedObjects.forEach((objectId) => {\n\t\t\tconst queue = this.#objectIdQueues.get(objectId);\n\t\t\tif (queue) {\n\t\t\t\tconflicts.add(objectId);\n\t\t\t\tthis.#objectIdQueues.get(objectId)!.push(() => {\n\t\t\t\t\tconflicts.delete(objectId);\n\t\t\t\t\tif (conflicts.size === 0) {\n\t\t\t\t\t\texecute();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthis.#objectIdQueues.set(objectId, []);\n\t\t\t}\n\t\t});\n\n\t\tif (conflicts.size === 0) {\n\t\t\texecute();\n\t\t}\n\n\t\treturn promise;\n\t}\n\n\tasync #getUsedObjects(transaction: Transaction) {\n\t\tconst usedObjects = new Set<string>();\n\t\tlet serialized = false;\n\n\t\ttransaction.addSerializationPlugin(async (blockData, _options, next) => {\n\t\t\tawait next();\n\n\t\t\tif (serialized) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tserialized = true;\n\n\t\t\tblockData.inputs.forEach((input) => {\n\t\t\t\tif (input.Object?.ImmOrOwnedObject?.objectId) {\n\t\t\t\t\tusedObjects.add(input.Object.ImmOrOwnedObject.objectId);\n\t\t\t\t} else if (input.Object?.Receiving?.objectId) {\n\t\t\t\t\tusedObjects.add(input.Object.Receiving.objectId);\n\t\t\t\t} else if (\n\t\t\t\t\tinput.UnresolvedObject?.objectId &&\n\t\t\t\t\t!input.UnresolvedObject.initialSharedVersion\n\t\t\t\t) {\n\t\t\t\t\tusedObjects.add(input.UnresolvedObject.objectId);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\tawait transaction.prepareForSerialization({ client: this.#client });\n\n\t\treturn usedObjects;\n\t}\n\n\tasync #execute<Include extends HaneulClientTypes.TransactionInclude = {}>(\n\t\ttransaction: Transaction,\n\t\tusedObjects: Set<string>,\n\t\tinclude?: Include,\n\t\tadditionalSignatures: string[] = [],\n\t): Promise<HaneulClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\tlet gasCoin: CoinWithBalance | null = null;\n\t\ttry {\n\t\t\ttransaction.setSenderIfNotSet(this.#signer.toHaneulAddress());\n\n\t\t\tawait this.#buildQueue.runTask(async () => {\n\t\t\t\tconst data = transaction.getData();\n\n\t\t\t\tif (!data.gasData.price) {\n\t\t\t\t\ttransaction.setGasPrice(await this.#getGasPrice());\n\t\t\t\t}\n\n\t\t\t\ttransaction.setGasBudgetIfNotSet(this.#defaultGasBudget);\n\n\t\t\t\tawait this.#updateCache();\n\t\t\t\tthis.#pendingTransactions++;\n\n\t\t\t\tif (this.#gasMode === 'addressBalance') {\n\t\t\t\t\t// Address balance mode: use empty gas payment with ValidDuring expiration\n\t\t\t\t\ttransaction.setGasPayment([]);\n\t\t\t\t\ttransaction.setExpiration(await this.#getValidDuringExpiration());\n\t\t\t\t} else {\n\t\t\t\t\t// Coin mode: use gas coin from pool\n\t\t\t\t\tgasCoin = await this.#getGasCoin();\n\t\t\t\t\ttransaction.setGasPayment([\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tobjectId: gasCoin.id,\n\t\t\t\t\t\t\tversion: gasCoin.version,\n\t\t\t\t\t\t\tdigest: gasCoin.digest,\n\t\t\t\t\t\t},\n\t\t\t\t\t]);\n\t\t\t\t}\n\n\t\t\t\t// Resolve cached references\n\t\t\t\tawait this.#cache.buildTransaction({ transaction, onlyTransactionKind: true });\n\t\t\t});\n\n\t\t\tconst bytes = await transaction.build({ client: this.#client });\n\n\t\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\n\t\t\tconst results = await this.#cache.executeTransaction({\n\t\t\t\ttransaction: bytes,\n\t\t\t\tsignatures: [signature, ...additionalSignatures],\n\t\t\t\tinclude,\n\t\t\t});\n\n\t\t\tconst tx = results.$kind === 'Transaction' ? results.Transaction : results.FailedTransaction;\n\t\t\tconst effects = tx.effects!;\n\t\t\tconst gasObject = effects.gasObject;\n\t\t\tconst gasUsed = effects.gasUsed;\n\n\t\t\tif (gasCoin && gasUsed && gasObject) {\n\t\t\t\tconst coin = gasCoin as CoinWithBalance;\n\t\t\t\tconst gasOwner = gasObject.outputOwner?.AddressOwner ?? gasObject.outputOwner?.ObjectOwner;\n\n\t\t\t\tif (gasOwner === this.#signer.toHaneulAddress()) {\n\t\t\t\t\tconst totalUsed =\n\t\t\t\t\t\tBigInt(gasUsed.computationCost) +\n\t\t\t\t\t\tBigInt(gasUsed.storageCost) +\n\t\t\t\t\t\tBigInt(gasUsed.storageCost) -\n\t\t\t\t\t\tBigInt(gasUsed.storageRebate);\n\t\t\t\t\tconst remainingBalance = coin.balance - totalUsed;\n\n\t\t\t\t\tlet usesGasCoin = false;\n\t\t\t\t\tnew TransactionDataBuilder(transaction.getData()).mapArguments((arg) => {\n\t\t\t\t\t\tif (arg.$kind === 'GasCoin') {\n\t\t\t\t\t\t\tusesGasCoin = true;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn arg;\n\t\t\t\t\t});\n\n\t\t\t\t\tconst gasRef = {\n\t\t\t\t\t\tobjectId: gasObject.objectId,\n\t\t\t\t\t\tversion: gasObject.outputVersion!,\n\t\t\t\t\t\tdigest: gasObject.outputDigest!,\n\t\t\t\t\t};\n\n\t\t\t\t\tif (!usesGasCoin && remainingBalance >= this.#minimumCoinBalance) {\n\t\t\t\t\t\tthis.#coinPool.push({\n\t\t\t\t\t\t\tid: gasRef.objectId,\n\t\t\t\t\t\t\tversion: gasRef.version,\n\t\t\t\t\t\t\tdigest: gasRef.digest,\n\t\t\t\t\t\t\tbalance: remainingBalance,\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (!this.#sourceCoins) {\n\t\t\t\t\t\t\tthis.#sourceCoins = new Map();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.#sourceCoins.set(gasRef.objectId, gasRef);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.#lastDigest = tx.digest;\n\n\t\t\treturn results as HaneulClientTypes.TransactionResult<Include & { effects: true }>;\n\t\t} catch (error) {\n\t\t\tif (gasCoin) {\n\t\t\t\tif (!this.#sourceCoins) {\n\t\t\t\t\tthis.#sourceCoins = new Map();\n\t\t\t\t}\n\n\t\t\t\tthis.#sourceCoins.set((gasCoin as CoinWithBalance).id, null);\n\t\t\t}\n\n\t\t\tawait this.#updateCache(async () => {\n\t\t\t\tawait Promise.all([\n\t\t\t\t\tthis.#cache.cache.deleteObjects([...usedObjects]),\n\t\t\t\t\tthis.#waitForLastDigest(),\n\t\t\t\t]);\n\t\t\t});\n\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tusedObjects.forEach((objectId) => {\n\t\t\t\tconst queue = this.#objectIdQueues.get(objectId);\n\t\t\t\tif (queue && queue.length > 0) {\n\t\t\t\t\tqueue.shift()!();\n\t\t\t\t} else if (queue) {\n\t\t\t\t\tthis.#objectIdQueues.delete(objectId);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis.#pendingTransactions--;\n\t\t}\n\t}\n\n\t/** Helper for synchronizing cache updates, by ensuring only one update happens at a time. This can also be used to wait for any pending cache updates */\n\tasync #updateCache(fn?: () => Promise<void>) {\n\t\tif (this.#cacheLock) {\n\t\t\tawait this.#cacheLock;\n\t\t}\n\n\t\tthis.#cacheLock =\n\t\t\tfn?.().then(\n\t\t\t\t() => {\n\t\t\t\t\tthis.#cacheLock = null;\n\t\t\t\t},\n\t\t\t\t() => {},\n\t\t\t) ?? null;\n\t}\n\n\tasync #waitForLastDigest() {\n\t\tconst digest = this.#lastDigest;\n\t\tif (digest) {\n\t\t\tthis.#lastDigest = null;\n\t\t\tawait this.#client.core.waitForTransaction({ digest });\n\t\t}\n\t}\n\n\tasync #getGasCoin() {\n\t\tif (this.#coinPool.length === 0 && this.#pendingTransactions <= this.#maxPoolSize) {\n\t\t\tawait this.#refillCoinPool();\n\t\t}\n\n\t\tif (this.#coinPool.length === 0) {\n\t\t\tthrow new Error('No coins available');\n\t\t}\n\n\t\tconst coin = this.#coinPool.shift()!;\n\t\treturn coin;\n\t}\n\n\tasync #getGasPrice(): Promise<bigint> {\n\t\tawait this.#ensureEpochInfo();\n\t\treturn this.#epochInfo!.price;\n\t}\n\n\tasync #getValidDuringExpiration() {\n\t\tawait this.#ensureEpochInfo();\n\t\tconst currentEpoch = BigInt(this.#epochInfo!.epoch);\n\t\treturn {\n\t\t\tValidDuring: {\n\t\t\t\tminEpoch: String(currentEpoch),\n\t\t\t\tmaxEpoch: String(currentEpoch + 1n),\n\t\t\t\tminTimestamp: null,\n\t\t\t\tmaxTimestamp: null,\n\t\t\t\tchain: this.#epochInfo!.chainIdentifier,\n\t\t\t\tnonce: (Math.random() * 0x100000000) >>> 0,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync #ensureEpochInfo(): Promise<void> {\n\t\tif (this.#epochInfo && this.#epochInfo.expiration - EPOCH_BOUNDARY_WINDOW - Date.now() > 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.#epochInfoPromise) {\n\t\t\tawait this.#epochInfoPromise;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#epochInfoPromise = this.#fetchEpochInfo();\n\t\ttry {\n\t\t\tawait this.#epochInfoPromise;\n\t\t} finally {\n\t\t\tthis.#epochInfoPromise = null;\n\t\t}\n\t}\n\n\tasync #fetchEpochInfo(): Promise<void> {\n\t\tconst [{ systemState }, { chainIdentifier }] = await Promise.all([\n\t\t\tthis.#client.core.getCurrentSystemState(),\n\t\t\tthis.#client.core.getChainIdentifier(),\n\t\t]);\n\n\t\tthis.#epochInfo = {\n\t\t\tepoch: systemState.epoch,\n\t\t\tprice: BigInt(systemState.referenceGasPrice),\n\t\t\texpiration:\n\t\t\t\tNumber(systemState.epochStartTimestampMs) + Number(systemState.parameters.epochDurationMs),\n\t\t\tchainIdentifier,\n\t\t};\n\t}\n\n\tasync #refillCoinPool() {\n\t\tconst batchSize = Math.min(\n\t\t\tthis.#coinBatchSize,\n\t\t\tthis.#maxPoolSize - (this.#coinPool.length + this.#pendingTransactions) + 1,\n\t\t);\n\n\t\tif (batchSize === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst txb = new Transaction();\n\t\tconst address = this.#signer.toHaneulAddress();\n\t\ttxb.setSender(address);\n\n\t\tif (this.#sourceCoins) {\n\t\t\tconst refs = [];\n\t\t\tconst ids = [];\n\t\t\tfor (const [id, ref] of this.#sourceCoins) {\n\t\t\t\tif (ref) {\n\t\t\t\t\trefs.push(ref);\n\t\t\t\t} else {\n\t\t\t\t\tids.push(id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (ids.length > 0) {\n\t\t\t\tconst { objects } = await this.#client.core.getObjects({\n\t\t\t\t\tobjectIds: ids,\n\t\t\t\t});\n\t\t\t\trefs.push(\n\t\t\t\t\t...objects\n\t\t\t\t\t\t.filter((obj): obj is HaneulClientTypes.Object => !(obj instanceof Error))\n\t\t\t\t\t\t.map((obj) => ({\n\t\t\t\t\t\t\tobjectId: obj.objectId,\n\t\t\t\t\t\t\tversion: obj.version,\n\t\t\t\t\t\t\tdigest: obj.digest,\n\t\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\ttxb.setGasPayment(refs);\n\t\t\tthis.#sourceCoins = new Map();\n\t\t}\n\n\t\tconst amounts = new Array(batchSize).fill(this.#initialCoinBalance);\n\t\tconst splitResults = txb.splitCoins(txb.gas, amounts);\n\t\tconst coinResults = [];\n\t\tfor (let i = 0; i < amounts.length; i++) {\n\t\t\tcoinResults.push(splitResults[i]);\n\t\t}\n\t\ttxb.transferObjects(coinResults, address);\n\n\t\tawait this.waitForLastTransaction();\n\n\t\ttxb.addBuildPlugin(coreClientResolveTransactionPlugin);\n\t\tconst bytes = await txb.build({ client: this.#client });\n\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\n\t\tconst result = await this.#client.core.executeTransaction({\n\t\t\ttransaction: bytes,\n\t\t\tsignatures: [signature],\n\t\t\tinclude: { effects: true },\n\t\t});\n\n\t\tconst tx = result.$kind === 'Transaction' ? result.Transaction : result.FailedTransaction;\n\t\tconst effects = tx.effects!;\n\n\t\teffects.changedObjects.forEach((changedObj) => {\n\t\t\tif (\n\t\t\t\tchangedObj.objectId === effects.gasObject?.objectId ||\n\t\t\t\tchangedObj.outputState !== 'ObjectWrite'\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.#coinPool.push({\n\t\t\t\tid: changedObj.objectId,\n\t\t\t\tversion: changedObj.outputVersion!,\n\t\t\t\tdigest: changedObj.outputDigest!,\n\t\t\t\tbalance: BigInt(this.#initialCoinBalance),\n\t\t\t});\n\t\t});\n\n\t\tif (!this.#sourceCoins) {\n\t\t\tthis.#sourceCoins = new Map();\n\t\t}\n\n\t\tconst gasObject = effects.gasObject!;\n\t\tthis.#sourceCoins!.set(gasObject.objectId, {\n\t\t\tobjectId: gasObject.objectId,\n\t\t\tversion: gasObject.outputVersion!,\n\t\t\tdigest: gasObject.outputDigest!,\n\t\t});\n\n\t\tawait this.#client.core.waitForTransaction({ digest: tx.digest });\n\t}\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,6BAA6B;CAClC,eAAe;CACf,oBAAoB;CACpB,oBAAoB;CACpB,aAAa;CACb;AAED,MAAM,wBAAwB;AAwC9B,IAAa,8BAAb,MAAyC;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,YAA+B,EAAE;CACjC;CACA,kCAAkB,IAAI,KAA6B;CACnD,cAAc,IAAI,aAAa;CAC/B;CACA,cAA6B;CAC7B,aAAmC;CACnC,uBAAuB;CACvB,aAKI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AKE,YACT,OAAKA,8BAAe,IAAI,KAAK;EAG9B,MAAM,YAAY,QAAQ;AAC1B,QAAKA,YAAc,IAAI,UAAU,UAAU;GAC1C,UAAU,UAAU;GACpB,SAAS,UAAU;GACnB,QAAQ,UAAU;GAClB,CAAC;AAEF,QAAM,MAAKL,OAAQ,KAAK,mBAAmB,EAAE,QAAQ,GAAG,QAAQ,CAAC"}
@@ -51,7 +51,7 @@ var SerialTransactionExecutor = class {
51
51
  if (gasCoin) copy.setGasPayment([gasCoin]);
52
52
  }
53
53
  copy.setGasBudgetIfNotSet(this.#defaultGasBudget);
54
- copy.setSenderIfNotSet(this.#signer.toSuiAddress());
54
+ copy.setSenderIfNotSet(this.#signer.toHaneulAddress());
55
55
  return this.#cache.buildTransaction({ transaction: copy });
56
56
  };
57
57
  async #getValidDuringExpiration() {
@@ -1 +1 @@
1
- {"version":3,"file":"serial.mjs","names":["#signer","#client","#defaultGasBudget","#gasMode","#cache","#cacheGasCoin","#queue","#buildTransaction","#getValidDuringExpiration","#ensureEpochInfo","#epochInfo","#epochInfoPromise","#fetchEpochInfo"],"sources":["../../../src/transactions/executor/serial.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { bcs } from '../../bcs/index.js';\nimport type { ClientWithCoreApi } from '../../client/core.js';\nimport type { HaneulClientTypes } from '../../client/types.js';\nimport type { Signer } from '../../cryptography/keypair.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { isTransaction, Transaction } from '../Transaction.js';\nimport { CachingTransactionExecutor } from './caching.js';\nimport { SerialQueue } from './queue.js';\n\nconst EPOCH_BOUNDARY_WINDOW = 60_000;\n\ninterface SerialTransactionExecutorBaseOptions extends Omit<ObjectCacheOptions, 'address'> {\n\tclient: ClientWithCoreApi;\n\tsigner: Signer;\n\tdefaultGasBudget?: bigint;\n}\n\nexport interface SerialTransactionExecutorCoinOptions extends SerialTransactionExecutorBaseOptions {\n\tgasMode?: 'coins';\n}\n\nexport interface SerialTransactionExecutorAddressBalanceOptions extends SerialTransactionExecutorBaseOptions {\n\tgasMode: 'addressBalance';\n}\n\nexport type SerialTransactionExecutorOptions =\n\t| SerialTransactionExecutorCoinOptions\n\t| SerialTransactionExecutorAddressBalanceOptions;\n\nexport class SerialTransactionExecutor {\n\t#queue = new SerialQueue();\n\t#signer: Signer;\n\t#client: ClientWithCoreApi;\n\t#cache: CachingTransactionExecutor;\n\t#defaultGasBudget: bigint;\n\t#gasMode: 'coins' | 'addressBalance';\n\t#epochInfo: null | {\n\t\tepoch: string;\n\t\texpiration: number;\n\t\tchainIdentifier: string;\n\t} = null;\n\t#epochInfoPromise: Promise<void> | null = null;\n\n\tconstructor(options: SerialTransactionExecutorOptions) {\n\t\tconst { signer, defaultGasBudget = 50_000_000n, client, cache } = options;\n\t\tthis.#signer = signer;\n\t\tthis.#client = client;\n\t\tthis.#defaultGasBudget = defaultGasBudget;\n\t\tthis.#gasMode = options.gasMode ?? 'coins';\n\t\tthis.#cache = new CachingTransactionExecutor({\n\t\t\tclient,\n\t\t\tcache,\n\t\t\tonEffects: (effects) => this.#cacheGasCoin(effects),\n\t\t});\n\t}\n\n\tasync applyEffects(effects: typeof bcs.TransactionEffects.$inferType) {\n\t\treturn this.#cache.applyEffects(effects);\n\t}\n\n\t#cacheGasCoin = async (effects: typeof bcs.TransactionEffects.$inferType) => {\n\t\tif (this.#gasMode === 'addressBalance' || !effects.V2) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst gasCoin = getGasCoinFromEffects(effects).ref;\n\t\tif (gasCoin) {\n\t\t\tthis.#cache.cache.setCustom('gasCoin', gasCoin);\n\t\t} else {\n\t\t\tthis.#cache.cache.deleteCustom('gasCoin');\n\t\t}\n\t};\n\n\tasync buildTransaction(transaction: Transaction) {\n\t\treturn this.#queue.runTask(() => this.#buildTransaction(transaction));\n\t}\n\n\t#buildTransaction = async (transaction: Transaction) => {\n\t\tawait transaction.prepareForSerialization({\n\t\t\tclient: this.#client,\n\t\t\tsupportedIntents: ['CoinWithBalance'],\n\t\t});\n\t\tconst copy = Transaction.from(transaction);\n\n\t\tif (this.#gasMode === 'addressBalance') {\n\t\t\tcopy.setGasPayment([]);\n\t\t\tcopy.setExpiration(await this.#getValidDuringExpiration());\n\t\t} else {\n\t\t\t// Coin mode: use cached gas coin if available\n\t\t\tconst gasCoin = await this.#cache.cache.getCustom<{\n\t\t\t\tobjectId: string;\n\t\t\t\tversion: string;\n\t\t\t\tdigest: string;\n\t\t\t}>('gasCoin');\n\n\t\t\tif (gasCoin) {\n\t\t\t\tcopy.setGasPayment([gasCoin]);\n\t\t\t}\n\t\t}\n\n\t\tcopy.setGasBudgetIfNotSet(this.#defaultGasBudget);\n\t\tcopy.setSenderIfNotSet(this.#signer.toSuiAddress());\n\n\t\treturn this.#cache.buildTransaction({ transaction: copy });\n\t};\n\n\tasync #getValidDuringExpiration() {\n\t\tawait this.#ensureEpochInfo();\n\t\tconst currentEpoch = BigInt(this.#epochInfo!.epoch);\n\t\treturn {\n\t\t\tValidDuring: {\n\t\t\t\tminEpoch: String(currentEpoch),\n\t\t\t\tmaxEpoch: String(currentEpoch + 1n),\n\t\t\t\tminTimestamp: null,\n\t\t\t\tmaxTimestamp: null,\n\t\t\t\tchain: this.#epochInfo!.chainIdentifier,\n\t\t\t\tnonce: (Math.random() * 0x100000000) >>> 0,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync #ensureEpochInfo(): Promise<void> {\n\t\tif (this.#epochInfo && this.#epochInfo.expiration - EPOCH_BOUNDARY_WINDOW - Date.now() > 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.#epochInfoPromise) {\n\t\t\tawait this.#epochInfoPromise;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#epochInfoPromise = this.#fetchEpochInfo();\n\t\ttry {\n\t\t\tawait this.#epochInfoPromise;\n\t\t} finally {\n\t\t\tthis.#epochInfoPromise = null;\n\t\t}\n\t}\n\n\tasync #fetchEpochInfo(): Promise<void> {\n\t\tconst [{ systemState }, { chainIdentifier }] = await Promise.all([\n\t\t\tthis.#client.core.getCurrentSystemState(),\n\t\t\tthis.#client.core.getChainIdentifier(),\n\t\t]);\n\n\t\tthis.#epochInfo = {\n\t\t\tepoch: systemState.epoch,\n\t\t\texpiration:\n\t\t\t\tNumber(systemState.epochStartTimestampMs) + Number(systemState.parameters.epochDurationMs),\n\t\t\tchainIdentifier,\n\t\t};\n\t}\n\n\tresetCache() {\n\t\treturn this.#cache.reset();\n\t}\n\n\twaitForLastTransaction() {\n\t\treturn this.#cache.waitForLastTransaction();\n\t}\n\n\texecuteTransaction<Include extends HaneulClientTypes.TransactionInclude = {}>(\n\t\ttransaction: Transaction | Uint8Array,\n\t\tinclude?: Include,\n\t\tadditionalSignatures: string[] = [],\n\t): Promise<HaneulClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\treturn this.#queue.runTask(async () => {\n\t\t\tconst bytes = isTransaction(transaction)\n\t\t\t\t? await this.#buildTransaction(transaction)\n\t\t\t\t: transaction;\n\n\t\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\t\t\treturn this.#cache\n\t\t\t\t.executeTransaction({\n\t\t\t\t\tsignatures: [signature, ...additionalSignatures],\n\t\t\t\t\ttransaction: bytes,\n\t\t\t\t\tinclude,\n\t\t\t\t})\n\t\t\t\t.catch(async (error) => {\n\t\t\t\t\tawait this.resetCache();\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\t});\n\t}\n}\n\nexport function getGasCoinFromEffects(effects: typeof bcs.TransactionEffects.$inferType) {\n\tif (!effects.V2) {\n\t\tthrow new Error('Unexpected effects version');\n\t}\n\n\tconst gasObjectChange = effects.V2.changedObjects[effects.V2.gasObjectIndex!];\n\n\tif (!gasObjectChange) {\n\t\tthrow new Error('Gas object not found in effects');\n\t}\n\n\tconst [objectId, { outputState }] = gasObjectChange;\n\n\tif (!outputState.ObjectWrite) {\n\t\tthrow new Error('Unexpected gas object state');\n\t}\n\n\tconst [digest, owner] = outputState.ObjectWrite;\n\n\treturn {\n\t\tref: {\n\t\t\tobjectId,\n\t\t\tdigest,\n\t\t\tversion: effects.V2.lamportVersion,\n\t\t},\n\t\towner: owner.AddressOwner || owner.ObjectOwner!,\n\t};\n}\n"],"mappings":";;;;;AAYA,MAAM,wBAAwB;AAoB9B,IAAa,4BAAb,MAAuC;CACtC,SAAS,IAAI,aAAa;CAC1B;CACA;CACA;CACA;CACA;CACA,aAII;CACJ,oBAA0C;CAE1C,YAAY,SAA2C;EACtD,MAAM,EAAE,QAAQ,mBAAmB,WAAa,QAAQ,UAAU;AAClE,QAAKA,SAAU;AACf,QAAKC,SAAU;AACf,QAAKC,mBAAoB;AACzB,QAAKC,UAAW,QAAQ,WAAW;AACnC,QAAKC,QAAS,IAAI,2BAA2B;GAC5C;GACA;GACA,YAAY,YAAY,MAAKC,aAAc,QAAQ;GACnD,CAAC;;CAGH,MAAM,aAAa,SAAmD;AACrE,SAAO,MAAKD,MAAO,aAAa,QAAQ;;CAGzC,gBAAgB,OAAO,YAAsD;AAC5E,MAAI,MAAKD,YAAa,oBAAoB,CAAC,QAAQ,GAClD;EAGD,MAAM,UAAU,sBAAsB,QAAQ,CAAC;AAC/C,MAAI,QACH,OAAKC,MAAO,MAAM,UAAU,WAAW,QAAQ;MAE/C,OAAKA,MAAO,MAAM,aAAa,UAAU;;CAI3C,MAAM,iBAAiB,aAA0B;AAChD,SAAO,MAAKE,MAAO,cAAc,MAAKC,iBAAkB,YAAY,CAAC;;CAGtE,oBAAoB,OAAO,gBAA6B;AACvD,QAAM,YAAY,wBAAwB;GACzC,QAAQ,MAAKN;GACb,kBAAkB,CAAC,kBAAkB;GACrC,CAAC;EACF,MAAM,OAAO,YAAY,KAAK,YAAY;AAE1C,MAAI,MAAKE,YAAa,kBAAkB;AACvC,QAAK,cAAc,EAAE,CAAC;AACtB,QAAK,cAAc,MAAM,MAAKK,0BAA2B,CAAC;SACpD;GAEN,MAAM,UAAU,MAAM,M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,YAAY,GACrC,MAAM,MAAKC,iBAAkB,YAAY,GACzC;GAEH,MAAM,EAAE,cAAc,MAAM,MAAKP,OAAQ,gBAAgB,MAAM;AAC/D,UAAO,MAAKI,MACV,mBAAmB;IACnB,YAAY,CAAC,WAAW,GAAG,qBAAqB;IAChD,aAAa;IACb;IACA,CAAC,CACD,MAAM,OAAO,UAAU;AACvB,UAAM,KAAK,YAAY;AACvB,UAAM;KACL;IACF;;;AAIJ,SAAgB,sBAAsB,SAAmD;AACxF,KAAI,CAAC,QAAQ,GACZ,OAAM,IAAI,MAAM,6BAA6B;CAG9C,MAAM,kBAAkB,QAAQ,GAAG,eAAe,QAAQ,GAAG;AAE7D,KAAI,CAAC,gBACJ,OAAM,IAAI,MAAM,kCAAkC;CAGnD,MAAM,CAAC,UAAU,EAAE,iBAAiB;AAEpC,KAAI,CAAC,YAAY,YAChB,OAAM,IAAI,MAAM,8BAA8B;CAG/C,MAAM,CAAC,QAAQ,SAAS,YAAY;AAEpC,QAAO;EACN,KAAK;GACJ;GACA;GACA,SAAS,QAAQ,GAAG;GACpB;EACD,OAAO,MAAM,gBAAgB,MAAM;EACnC"}
1
+ {"version":3,"file":"serial.mjs","names":["#signer","#client","#defaultGasBudget","#gasMode","#cache","#cacheGasCoin","#queue","#buildTransaction","#getValidDuringExpiration","#ensureEpochInfo","#epochInfo","#epochInfoPromise","#fetchEpochInfo"],"sources":["../../../src/transactions/executor/serial.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { bcs } from '../../bcs/index.js';\nimport type { ClientWithCoreApi } from '../../client/core.js';\nimport type { HaneulClientTypes } from '../../client/types.js';\nimport type { Signer } from '../../cryptography/keypair.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { isTransaction, Transaction } from '../Transaction.js';\nimport { CachingTransactionExecutor } from './caching.js';\nimport { SerialQueue } from './queue.js';\n\nconst EPOCH_BOUNDARY_WINDOW = 60_000;\n\ninterface SerialTransactionExecutorBaseOptions extends Omit<ObjectCacheOptions, 'address'> {\n\tclient: ClientWithCoreApi;\n\tsigner: Signer;\n\tdefaultGasBudget?: bigint;\n}\n\nexport interface SerialTransactionExecutorCoinOptions extends SerialTransactionExecutorBaseOptions {\n\tgasMode?: 'coins';\n}\n\nexport interface SerialTransactionExecutorAddressBalanceOptions extends SerialTransactionExecutorBaseOptions {\n\tgasMode: 'addressBalance';\n}\n\nexport type SerialTransactionExecutorOptions =\n\t| SerialTransactionExecutorCoinOptions\n\t| SerialTransactionExecutorAddressBalanceOptions;\n\nexport class SerialTransactionExecutor {\n\t#queue = new SerialQueue();\n\t#signer: Signer;\n\t#client: ClientWithCoreApi;\n\t#cache: CachingTransactionExecutor;\n\t#defaultGasBudget: bigint;\n\t#gasMode: 'coins' | 'addressBalance';\n\t#epochInfo: null | {\n\t\tepoch: string;\n\t\texpiration: number;\n\t\tchainIdentifier: string;\n\t} = null;\n\t#epochInfoPromise: Promise<void> | null = null;\n\n\tconstructor(options: SerialTransactionExecutorOptions) {\n\t\tconst { signer, defaultGasBudget = 50_000_000n, client, cache } = options;\n\t\tthis.#signer = signer;\n\t\tthis.#client = client;\n\t\tthis.#defaultGasBudget = defaultGasBudget;\n\t\tthis.#gasMode = options.gasMode ?? 'coins';\n\t\tthis.#cache = new CachingTransactionExecutor({\n\t\t\tclient,\n\t\t\tcache,\n\t\t\tonEffects: (effects) => this.#cacheGasCoin(effects),\n\t\t});\n\t}\n\n\tasync applyEffects(effects: typeof bcs.TransactionEffects.$inferType) {\n\t\treturn this.#cache.applyEffects(effects);\n\t}\n\n\t#cacheGasCoin = async (effects: typeof bcs.TransactionEffects.$inferType) => {\n\t\tif (this.#gasMode === 'addressBalance' || !effects.V2) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst gasCoin = getGasCoinFromEffects(effects).ref;\n\t\tif (gasCoin) {\n\t\t\tthis.#cache.cache.setCustom('gasCoin', gasCoin);\n\t\t} else {\n\t\t\tthis.#cache.cache.deleteCustom('gasCoin');\n\t\t}\n\t};\n\n\tasync buildTransaction(transaction: Transaction) {\n\t\treturn this.#queue.runTask(() => this.#buildTransaction(transaction));\n\t}\n\n\t#buildTransaction = async (transaction: Transaction) => {\n\t\tawait transaction.prepareForSerialization({\n\t\t\tclient: this.#client,\n\t\t\tsupportedIntents: ['CoinWithBalance'],\n\t\t});\n\t\tconst copy = Transaction.from(transaction);\n\n\t\tif (this.#gasMode === 'addressBalance') {\n\t\t\tcopy.setGasPayment([]);\n\t\t\tcopy.setExpiration(await this.#getValidDuringExpiration());\n\t\t} else {\n\t\t\t// Coin mode: use cached gas coin if available\n\t\t\tconst gasCoin = await this.#cache.cache.getCustom<{\n\t\t\t\tobjectId: string;\n\t\t\t\tversion: string;\n\t\t\t\tdigest: string;\n\t\t\t}>('gasCoin');\n\n\t\t\tif (gasCoin) {\n\t\t\t\tcopy.setGasPayment([gasCoin]);\n\t\t\t}\n\t\t}\n\n\t\tcopy.setGasBudgetIfNotSet(this.#defaultGasBudget);\n\t\tcopy.setSenderIfNotSet(this.#signer.toHaneulAddress());\n\n\t\treturn this.#cache.buildTransaction({ transaction: copy });\n\t};\n\n\tasync #getValidDuringExpiration() {\n\t\tawait this.#ensureEpochInfo();\n\t\tconst currentEpoch = BigInt(this.#epochInfo!.epoch);\n\t\treturn {\n\t\t\tValidDuring: {\n\t\t\t\tminEpoch: String(currentEpoch),\n\t\t\t\tmaxEpoch: String(currentEpoch + 1n),\n\t\t\t\tminTimestamp: null,\n\t\t\t\tmaxTimestamp: null,\n\t\t\t\tchain: this.#epochInfo!.chainIdentifier,\n\t\t\t\tnonce: (Math.random() * 0x100000000) >>> 0,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync #ensureEpochInfo(): Promise<void> {\n\t\tif (this.#epochInfo && this.#epochInfo.expiration - EPOCH_BOUNDARY_WINDOW - Date.now() > 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.#epochInfoPromise) {\n\t\t\tawait this.#epochInfoPromise;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#epochInfoPromise = this.#fetchEpochInfo();\n\t\ttry {\n\t\t\tawait this.#epochInfoPromise;\n\t\t} finally {\n\t\t\tthis.#epochInfoPromise = null;\n\t\t}\n\t}\n\n\tasync #fetchEpochInfo(): Promise<void> {\n\t\tconst [{ systemState }, { chainIdentifier }] = await Promise.all([\n\t\t\tthis.#client.core.getCurrentSystemState(),\n\t\t\tthis.#client.core.getChainIdentifier(),\n\t\t]);\n\n\t\tthis.#epochInfo = {\n\t\t\tepoch: systemState.epoch,\n\t\t\texpiration:\n\t\t\t\tNumber(systemState.epochStartTimestampMs) + Number(systemState.parameters.epochDurationMs),\n\t\t\tchainIdentifier,\n\t\t};\n\t}\n\n\tresetCache() {\n\t\treturn this.#cache.reset();\n\t}\n\n\twaitForLastTransaction() {\n\t\treturn this.#cache.waitForLastTransaction();\n\t}\n\n\texecuteTransaction<Include extends HaneulClientTypes.TransactionInclude = {}>(\n\t\ttransaction: Transaction | Uint8Array,\n\t\tinclude?: Include,\n\t\tadditionalSignatures: string[] = [],\n\t): Promise<HaneulClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\treturn this.#queue.runTask(async () => {\n\t\t\tconst bytes = isTransaction(transaction)\n\t\t\t\t? await this.#buildTransaction(transaction)\n\t\t\t\t: transaction;\n\n\t\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\t\t\treturn this.#cache\n\t\t\t\t.executeTransaction({\n\t\t\t\t\tsignatures: [signature, ...additionalSignatures],\n\t\t\t\t\ttransaction: bytes,\n\t\t\t\t\tinclude,\n\t\t\t\t})\n\t\t\t\t.catch(async (error) => {\n\t\t\t\t\tawait this.resetCache();\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\t});\n\t}\n}\n\nexport function getGasCoinFromEffects(effects: typeof bcs.TransactionEffects.$inferType) {\n\tif (!effects.V2) {\n\t\tthrow new Error('Unexpected effects version');\n\t}\n\n\tconst gasObjectChange = effects.V2.changedObjects[effects.V2.gasObjectIndex!];\n\n\tif (!gasObjectChange) {\n\t\tthrow new Error('Gas object not found in effects');\n\t}\n\n\tconst [objectId, { outputState }] = gasObjectChange;\n\n\tif (!outputState.ObjectWrite) {\n\t\tthrow new Error('Unexpected gas object state');\n\t}\n\n\tconst [digest, owner] = outputState.ObjectWrite;\n\n\treturn {\n\t\tref: {\n\t\t\tobjectId,\n\t\t\tdigest,\n\t\t\tversion: effects.V2.lamportVersion,\n\t\t},\n\t\towner: owner.AddressOwner || owner.ObjectOwner!,\n\t};\n}\n"],"mappings":";;;;;AAYA,MAAM,wBAAwB;AAoB9B,IAAa,4BAAb,MAAuC;CACtC,SAAS,IAAI,aAAa;CAC1B;CACA;CACA;CACA;CACA;CACA,aAII;CACJ,oBAA0C;CAE1C,YAAY,SAA2C;EACtD,MAAM,EAAE,QAAQ,mBAAmB,WAAa,QAAQ,UAAU;AAClE,QAAKA,SAAU;AACf,QAAKC,SAAU;AACf,QAAKC,mBAAoB;AACzB,QAAKC,UAAW,QAAQ,WAAW;AACnC,QAAKC,QAAS,IAAI,2BAA2B;GAC5C;GACA;GACA,YAAY,YAAY,MAAKC,aAAc,QAAQ;GACnD,CAAC;;CAGH,MAAM,aAAa,SAAmD;AACrE,SAAO,MAAKD,MAAO,aAAa,QAAQ;;CAGzC,gBAAgB,OAAO,YAAsD;AAC5E,MAAI,MAAKD,YAAa,oBAAoB,CAAC,QAAQ,GAClD;EAGD,MAAM,UAAU,sBAAsB,QAAQ,CAAC;AAC/C,MAAI,QACH,OAAKC,MAAO,MAAM,UAAU,WAAW,QAAQ;MAE/C,OAAKA,MAAO,MAAM,aAAa,UAAU;;CAI3C,MAAM,iBAAiB,aAA0B;AAChD,SAAO,MAAKE,MAAO,cAAc,MAAKC,iBAAkB,YAAY,CAAC;;CAGtE,oBAAoB,OAAO,gBAA6B;AACvD,QAAM,YAAY,wBAAwB;GACzC,QAAQ,MAAKN;GACb,kBAAkB,CAAC,kBAAkB;GACrC,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,SAAO,MAAKN,MAAO,OAAO;;CAG3B,yBAAyB;AACxB,SAAO,MAAKA,MAAO,wBAAwB;;CAG5C,mBACC,aACA,SACA,uBAAiC,EAAE,EACyC;AAC5E,SAAO,MAAKE,MAAO,QAAQ,YAAY;GACtC,MAAM,QAAQ,cAAc,YAAY,GACrC,MAAM,MAAKC,iBAAkB,YAAY,GACzC;GAEH,MAAM,EAAE,cAAc,MAAM,MAAKP,OAAQ,gBAAgB,MAAM;AAC/D,UAAO,MAAKI,MACV,mBAAmB;IACnB,YAAY,CAAC,WAAW,GAAG,qBAAqB;IAChD,aAAa;IACb;IACA,CAAC,CACD,MAAM,OAAO,UAAU;AACvB,UAAM,KAAK,YAAY;AACvB,UAAM;KACL;IACF;;;AAIJ,SAAgB,sBAAsB,SAAmD;AACxF,KAAI,CAAC,QAAQ,GACZ,OAAM,IAAI,MAAM,6BAA6B;CAG9C,MAAM,kBAAkB,QAAQ,GAAG,eAAe,QAAQ,GAAG;AAE7D,KAAI,CAAC,gBACJ,OAAM,IAAI,MAAM,kCAAkC;CAGnD,MAAM,CAAC,UAAU,EAAE,iBAAiB;AAEpC,KAAI,CAAC,YAAY,YAChB,OAAM,IAAI,MAAM,8BAA8B;CAG/C,MAAM,CAAC,QAAQ,SAAS,YAAY;AAEpC,QAAO;EACN,KAAK;GACJ;GACA;GACA,SAAS,QAAQ,GAAG;GACpB;EACD,OAAO,MAAM,gBAAgB,MAAM;EACnC"}
@@ -25,7 +25,7 @@ declare function normalizeStructTag(type: string | StructTag): string;
25
25
  *
26
26
  */
27
27
  declare function normalizeHaneulAddress(value: string, forceAdd0x?: boolean): string;
28
- declare function normalizeSuiObjectId(value: string, forceAdd0x?: boolean): string;
28
+ declare function normalizeHaneulObjectId(value: string, forceAdd0x?: boolean): string;
29
29
  //#endregion
30
- export { HANEUL_ADDRESS_LENGTH, isValidHaneulAddress, isValidHaneulObjectId, isValidStructTag, isValidTransactionDigest, normalizeHaneulAddress, normalizeStructTag, normalizeSuiObjectId, parseStructTag };
30
+ export { HANEUL_ADDRESS_LENGTH, isValidHaneulAddress, isValidHaneulObjectId, isValidStructTag, isValidTransactionDigest, normalizeHaneulAddress, normalizeHaneulObjectId, normalizeStructTag, parseStructTag };
31
31
  //# sourceMappingURL=haneul-types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"haneul-types.d.mts","names":[],"sources":["../../src/utils/haneul-types.ts"],"sourcesContent":[],"mappings":";;AAUgB,iBAAA,wBAAA,CAAwB,KAAA,EAAA,MAAA,CAAA,EAAA,KAAA,IAAA,MAAA;AAe3B,cAAA,qBAAA,GAAqB,EAAA;AAClB,iBAAA,oBAAA,CAAoB,KAAA,EAAA,MAAA,CAAA,EAAA,KAAA,IAAA,MAAA;AAIpB,iBAAA,qBAAA,CAAqB,KAAA,EAAA,MAAA,CAAA,EAAA,OAAA;AA6DzB,iBATI,gBAAA,CAagB,IAAA,EAAA,MAAA,CAAA,EAAA,OAAA;AAShB,KAbJ,SAAA,GAakB;EA0Bd,OAAA,EAAA,MAAA;EA2BA,MAAA,EAAA,MAAA;EAQA,IAAA,EAAA,MAAA;wBAtEO;;iBASP,cAAA,gBAA8B;iBA0B9B,kBAAA,gBAAkC;;;;;;;;;;;;iBA2BlC,sBAAA;iBAQA,oBAAA"}
1
+ {"version":3,"file":"haneul-types.d.mts","names":[],"sources":["../../src/utils/haneul-types.ts"],"sourcesContent":[],"mappings":";;AAUgB,iBAAA,wBAAA,CAAwB,KAAA,EAAA,MAAA,CAAA,EAAA,KAAA,IAAA,MAAA;AAe3B,cAAA,qBAAA,GAAqB,EAAA;AAClB,iBAAA,oBAAA,CAAoB,KAAA,EAAA,MAAA,CAAA,EAAA,KAAA,IAAA,MAAA;AAIpB,iBAAA,qBAAA,CAAqB,KAAA,EAAA,MAAA,CAAA,EAAA,OAAA;AA6DzB,iBATI,gBAAA,CAagB,IAAA,EAAA,MAAA,CAAA,EAAA,OAAA;AAShB,KAbJ,SAAA,GAakB;EA0Bd,OAAA,EAAA,MAAA;EA2BA,MAAA,EAAA,MAAA;EAQA,IAAA,EAAA,MAAA;wBAtEO;;iBASP,cAAA,gBAA8B;iBA0B9B,kBAAA,gBAAkC;;;;;;;;;;;;iBA2BlC,sBAAA;iBAQA,uBAAA"}
@@ -95,7 +95,7 @@ function normalizeHaneulAddress(value, forceAdd0x = false) {
95
95
  if (!forceAdd0x && address.startsWith("0x")) address = address.slice(2);
96
96
  return `0x${address.padStart(HANEUL_ADDRESS_LENGTH * 2, "0")}`;
97
97
  }
98
- function normalizeSuiObjectId(value, forceAdd0x = false) {
98
+ function normalizeHaneulObjectId(value, forceAdd0x = false) {
99
99
  return normalizeHaneulAddress(value, forceAdd0x);
100
100
  }
101
101
  function isHex(value) {
@@ -106,5 +106,5 @@ function getHexByteLength(value) {
106
106
  }
107
107
 
108
108
  //#endregion
109
- export { HANEUL_ADDRESS_LENGTH, isValidHaneulAddress, isValidHaneulObjectId, isValidStructTag, isValidTransactionDigest, normalizeHaneulAddress, normalizeStructTag, normalizeSuiObjectId, parseStructTag };
109
+ export { HANEUL_ADDRESS_LENGTH, isValidHaneulAddress, isValidHaneulObjectId, isValidStructTag, isValidTransactionDigest, normalizeHaneulAddress, normalizeHaneulObjectId, normalizeStructTag, parseStructTag };
110
110
  //# sourceMappingURL=haneul-types.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"haneul-types.mjs","names":[],"sources":["../../src/utils/haneul-types.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase58, splitGenericParameters } from '@haneullabs/bcs';\n\nimport { isValidNamedPackage } from './move-registry.js';\n\nconst TX_DIGEST_LENGTH = 32;\n\n/** Returns whether the tx digest is valid based on the serialization format */\nexport function isValidTransactionDigest(value: string): value is string {\n\ttry {\n\t\tconst buffer = fromBase58(value);\n\t\treturn buffer.length === TX_DIGEST_LENGTH;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n// TODO - can we automatically sync this with rust length definition?\n// Source of truth is\n// https://github.com/GeunhwaJeong/haneul/blob/acb2b97ae21f47600e05b0d28127d88d0725561d/crate./haneul-types/src/base_types.rs#L67\n// which uses the Move account address length\n// https://github.com/move-language/move/blob/67ec40dc50c66c34fd73512fcc412f3b68d67235/language/move-core/types/src/account_address.rs#L23 .\n\nexport const HANEUL_ADDRESS_LENGTH = 32;\nexport function isValidHaneulAddress(value: string): value is string {\n\treturn isHex(value) && getHexByteLength(value) === HANEUL_ADDRESS_LENGTH;\n}\n\nexport function isValidHaneulObjectId(value: string): boolean {\n\treturn isValidHaneulAddress(value);\n}\n\nconst MOVE_IDENTIFIER_REGEX = /^[a-zA-Z][a-zA-Z0-9_]*$/;\n\nexport function isValidMoveIdentifier(name: string): boolean {\n\treturn MOVE_IDENTIFIER_REGEX.test(name);\n}\n\nconst PRIMITIVE_TYPE_TAGS = [\n\t'bool',\n\t'u8',\n\t'u16',\n\t'u32',\n\t'u64',\n\t'u128',\n\t'u256',\n\t'address',\n\t'signer',\n];\n\nconst VECTOR_TYPE_REGEX = /^vector<(.+)>$/;\n\nfunction isValidTypeTag(type: string): boolean {\n\tif (PRIMITIVE_TYPE_TAGS.includes(type)) return true;\n\n\tconst vectorMatch = type.match(VECTOR_TYPE_REGEX);\n\tif (vectorMatch) return isValidTypeTag(vectorMatch[1]);\n\n\tif (type.includes('::')) return isValidStructTag(type);\n\n\treturn false;\n}\n\nfunction isValidParsedStructTag(tag: StructTag): boolean {\n\tif (!isValidHaneulAddress(tag.address) && !isValidNamedPackage(tag.address)) {\n\t\treturn false;\n\t}\n\n\tif (!isValidMoveIdentifier(tag.module) || !isValidMoveIdentifier(tag.name)) {\n\t\treturn false;\n\t}\n\n\treturn tag.typeParams.every((param) => {\n\t\tif (typeof param === 'string') {\n\t\t\treturn isValidTypeTag(param);\n\t\t}\n\t\treturn isValidParsedStructTag(param);\n\t});\n}\n\nexport function isValidStructTag(type: string): boolean {\n\ttry {\n\t\tconst tag = parseStructTag(type);\n\t\treturn isValidParsedStructTag(tag);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport type StructTag = {\n\taddress: string;\n\tmodule: string;\n\tname: string;\n\ttypeParams: (string | StructTag)[];\n};\n\nfunction parseTypeTag(type: string): string | StructTag {\n\tif (!type.includes('::')) return type;\n\n\treturn parseStructTag(type);\n}\n\nexport function parseStructTag(type: string): StructTag {\n\tconst parts = type.split('::');\n\n\tif (parts.length < 3) {\n\t\tthrow new Error(`Invalid struct tag: ${type}`);\n\t}\n\n\tconst [address, module] = parts;\n\tconst isMvrPackage = isValidNamedPackage(address);\n\n\tconst rest = type.slice(address.length + module.length + 4);\n\tconst name = rest.includes('<') ? rest.slice(0, rest.indexOf('<')) : rest;\n\tconst typeParams = rest.includes('<')\n\t\t? splitGenericParameters(rest.slice(rest.indexOf('<') + 1, rest.lastIndexOf('>'))).map(\n\t\t\t\t(typeParam) => parseTypeTag(typeParam.trim()),\n\t\t\t)\n\t\t: [];\n\n\treturn {\n\t\taddress: isMvrPackage ? address : normalizeHaneulAddress(address),\n\t\tmodule,\n\t\tname,\n\t\ttypeParams,\n\t};\n}\n\nexport function normalizeStructTag(type: string | StructTag): string {\n\tconst { address, module, name, typeParams } =\n\t\ttypeof type === 'string' ? parseStructTag(type) : type;\n\n\tconst formattedTypeParams =\n\t\ttypeParams?.length > 0\n\t\t\t? `<${typeParams\n\t\t\t\t\t.map((typeParam) =>\n\t\t\t\t\t\ttypeof typeParam === 'string' ? typeParam : normalizeStructTag(typeParam),\n\t\t\t\t\t)\n\t\t\t\t\t.join(',')}>`\n\t\t\t: '';\n\n\treturn `${address}::${module}::${name}${formattedTypeParams}`;\n}\n\n/**\n * Perform the following operations:\n * 1. Make the address lower case\n * 2. Prepend `0x` if the string does not start with `0x`.\n * 3. Add more zeros if the length of the address(excluding `0x`) is less than `HANEUL_ADDRESS_LENGTH`\n *\n * WARNING: if the address value itself starts with `0x`, e.g., `0x0x`, the default behavior\n * is to treat the first `0x` not as part of the address. The default behavior can be overridden by\n * setting `forceAdd0x` to true\n *\n */\nexport function normalizeHaneulAddress(value: string, forceAdd0x: boolean = false): string {\n\tlet address = value.toLowerCase();\n\tif (!forceAdd0x && address.startsWith('0x')) {\n\t\taddress = address.slice(2);\n\t}\n\treturn `0x${address.padStart(HANEUL_ADDRESS_LENGTH * 2, '0')}`;\n}\n\nexport function normalizeSuiObjectId(value: string, forceAdd0x: boolean = false): string {\n\treturn normalizeHaneulAddress(value, forceAdd0x);\n}\n\nfunction isHex(value: string): boolean {\n\treturn /^(0x|0X)?[a-fA-F0-9]+$/.test(value) && value.length % 2 === 0;\n}\n\nfunction getHexByteLength(value: string): number {\n\treturn /^(0x|0X)/.test(value) ? (value.length - 2) / 2 : value.length / 2;\n}\n"],"mappings":";;;;AAOA,MAAM,mBAAmB;;AAGzB,SAAgB,yBAAyB,OAAgC;AACxE,KAAI;AAEH,SADe,WAAW,MAAM,CAClB,WAAW;SAClB;AACP,SAAO;;;AAUT,MAAa,wBAAwB;AACrC,SAAgB,qBAAqB,OAAgC;AACpE,QAAO,MAAM,MAAM,IAAI,iBAAiB,MAAM,KAAK;;AAGpD,SAAgB,sBAAsB,OAAwB;AAC7D,QAAO,qBAAqB,MAAM;;AAGnC,MAAM,wBAAwB;AAE9B,SAAgB,sBAAsB,MAAuB;AAC5D,QAAO,sBAAsB,KAAK,KAAK;;AAGxC,MAAM,sBAAsB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAED,MAAM,oBAAoB;AAE1B,SAAS,eAAe,MAAuB;AAC9C,KAAI,oBAAoB,SAAS,KAAK,CAAE,QAAO;CAE/C,MAAM,cAAc,KAAK,MAAM,kBAAkB;AACjD,KAAI,YAAa,QAAO,eAAe,YAAY,GAAG;AAEtD,KAAI,KAAK,SAAS,KAAK,CAAE,QAAO,iBAAiB,KAAK;AAEtD,QAAO;;AAGR,SAAS,uBAAuB,KAAyB;AACxD,KAAI,CAAC,qBAAqB,IAAI,QAAQ,IAAI,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H,KAAK,cACL,OAAO,cAAc,WAAW,YAAY,mBAAmB,UAAU,CACzE,CACA,KAAK,IAAI,CAAC,KACX;;;;;;;;;;;;;AAgBL,SAAgB,uBAAuB,OAAe,aAAsB,OAAe;CAC1F,IAAI,UAAU,MAAM,aAAa;AACjC,KAAI,CAAC,cAAc,QAAQ,WAAW,KAAK,CAC1C,WAAU,QAAQ,MAAM,EAAE;AAE3B,QAAO,KAAK,QAAQ,SAAS,wBAAwB,GAAG,IAAI;;AAG7D,SAAgB,qBAAqB,OAAe,aAAsB,OAAe;AACxF,QAAO,uBAAuB,OAAO,WAAW;;AAGjD,SAAS,MAAM,OAAwB;AACtC,QAAO,yBAAyB,KAAK,MAAM,IAAI,MAAM,SAAS,MAAM;;AAGrE,SAAS,iBAAiB,OAAuB;AAChD,QAAO,WAAW,KAAK,MAAM,IAAI,MAAM,SAAS,KAAK,IAAI,MAAM,SAAS"}
1
+ {"version":3,"file":"haneul-types.mjs","names":[],"sources":["../../src/utils/haneul-types.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase58, splitGenericParameters } from '@haneullabs/bcs';\n\nimport { isValidNamedPackage } from './move-registry.js';\n\nconst TX_DIGEST_LENGTH = 32;\n\n/** Returns whether the tx digest is valid based on the serialization format */\nexport function isValidTransactionDigest(value: string): value is string {\n\ttry {\n\t\tconst buffer = fromBase58(value);\n\t\treturn buffer.length === TX_DIGEST_LENGTH;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n// TODO - can we automatically sync this with rust length definition?\n// Source of truth is\n// https://github.com/GeunhwaJeong/haneul/blob/acb2b97ae21f47600e05b0d28127d88d0725561d/crate./haneul-types/src/base_types.rs#L67\n// which uses the Move account address length\n// https://github.com/move-language/move/blob/67ec40dc50c66c34fd73512fcc412f3b68d67235/language/move-core/types/src/account_address.rs#L23 .\n\nexport const HANEUL_ADDRESS_LENGTH = 32;\nexport function isValidHaneulAddress(value: string): value is string {\n\treturn isHex(value) && getHexByteLength(value) === HANEUL_ADDRESS_LENGTH;\n}\n\nexport function isValidHaneulObjectId(value: string): boolean {\n\treturn isValidHaneulAddress(value);\n}\n\nconst MOVE_IDENTIFIER_REGEX = /^[a-zA-Z][a-zA-Z0-9_]*$/;\n\nexport function isValidMoveIdentifier(name: string): boolean {\n\treturn MOVE_IDENTIFIER_REGEX.test(name);\n}\n\nconst PRIMITIVE_TYPE_TAGS = [\n\t'bool',\n\t'u8',\n\t'u16',\n\t'u32',\n\t'u64',\n\t'u128',\n\t'u256',\n\t'address',\n\t'signer',\n];\n\nconst VECTOR_TYPE_REGEX = /^vector<(.+)>$/;\n\nfunction isValidTypeTag(type: string): boolean {\n\tif (PRIMITIVE_TYPE_TAGS.includes(type)) return true;\n\n\tconst vectorMatch = type.match(VECTOR_TYPE_REGEX);\n\tif (vectorMatch) return isValidTypeTag(vectorMatch[1]);\n\n\tif (type.includes('::')) return isValidStructTag(type);\n\n\treturn false;\n}\n\nfunction isValidParsedStructTag(tag: StructTag): boolean {\n\tif (!isValidHaneulAddress(tag.address) && !isValidNamedPackage(tag.address)) {\n\t\treturn false;\n\t}\n\n\tif (!isValidMoveIdentifier(tag.module) || !isValidMoveIdentifier(tag.name)) {\n\t\treturn false;\n\t}\n\n\treturn tag.typeParams.every((param) => {\n\t\tif (typeof param === 'string') {\n\t\t\treturn isValidTypeTag(param);\n\t\t}\n\t\treturn isValidParsedStructTag(param);\n\t});\n}\n\nexport function isValidStructTag(type: string): boolean {\n\ttry {\n\t\tconst tag = parseStructTag(type);\n\t\treturn isValidParsedStructTag(tag);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport type StructTag = {\n\taddress: string;\n\tmodule: string;\n\tname: string;\n\ttypeParams: (string | StructTag)[];\n};\n\nfunction parseTypeTag(type: string): string | StructTag {\n\tif (!type.includes('::')) return type;\n\n\treturn parseStructTag(type);\n}\n\nexport function parseStructTag(type: string): StructTag {\n\tconst parts = type.split('::');\n\n\tif (parts.length < 3) {\n\t\tthrow new Error(`Invalid struct tag: ${type}`);\n\t}\n\n\tconst [address, module] = parts;\n\tconst isMvrPackage = isValidNamedPackage(address);\n\n\tconst rest = type.slice(address.length + module.length + 4);\n\tconst name = rest.includes('<') ? rest.slice(0, rest.indexOf('<')) : rest;\n\tconst typeParams = rest.includes('<')\n\t\t? splitGenericParameters(rest.slice(rest.indexOf('<') + 1, rest.lastIndexOf('>'))).map(\n\t\t\t\t(typeParam) => parseTypeTag(typeParam.trim()),\n\t\t\t)\n\t\t: [];\n\n\treturn {\n\t\taddress: isMvrPackage ? address : normalizeHaneulAddress(address),\n\t\tmodule,\n\t\tname,\n\t\ttypeParams,\n\t};\n}\n\nexport function normalizeStructTag(type: string | StructTag): string {\n\tconst { address, module, name, typeParams } =\n\t\ttypeof type === 'string' ? parseStructTag(type) : type;\n\n\tconst formattedTypeParams =\n\t\ttypeParams?.length > 0\n\t\t\t? `<${typeParams\n\t\t\t\t\t.map((typeParam) =>\n\t\t\t\t\t\ttypeof typeParam === 'string' ? typeParam : normalizeStructTag(typeParam),\n\t\t\t\t\t)\n\t\t\t\t\t.join(',')}>`\n\t\t\t: '';\n\n\treturn `${address}::${module}::${name}${formattedTypeParams}`;\n}\n\n/**\n * Perform the following operations:\n * 1. Make the address lower case\n * 2. Prepend `0x` if the string does not start with `0x`.\n * 3. Add more zeros if the length of the address(excluding `0x`) is less than `HANEUL_ADDRESS_LENGTH`\n *\n * WARNING: if the address value itself starts with `0x`, e.g., `0x0x`, the default behavior\n * is to treat the first `0x` not as part of the address. The default behavior can be overridden by\n * setting `forceAdd0x` to true\n *\n */\nexport function normalizeHaneulAddress(value: string, forceAdd0x: boolean = false): string {\n\tlet address = value.toLowerCase();\n\tif (!forceAdd0x && address.startsWith('0x')) {\n\t\taddress = address.slice(2);\n\t}\n\treturn `0x${address.padStart(HANEUL_ADDRESS_LENGTH * 2, '0')}`;\n}\n\nexport function normalizeHaneulObjectId(value: string, forceAdd0x: boolean = false): string {\n\treturn normalizeHaneulAddress(value, forceAdd0x);\n}\n\nfunction isHex(value: string): boolean {\n\treturn /^(0x|0X)?[a-fA-F0-9]+$/.test(value) && value.length % 2 === 0;\n}\n\nfunction getHexByteLength(value: string): number {\n\treturn /^(0x|0X)/.test(value) ? (value.length - 2) / 2 : value.length / 2;\n}\n"],"mappings":";;;;AAOA,MAAM,mBAAmB;;AAGzB,SAAgB,yBAAyB,OAAgC;AACxE,KAAI;AAEH,SADe,WAAW,MAAM,CAClB,WAAW;SAClB;AACP,SAAO;;;AAUT,MAAa,wBAAwB;AACrC,SAAgB,qBAAqB,OAAgC;AACpE,QAAO,MAAM,MAAM,IAAI,iBAAiB,MAAM,KAAK;;AAGpD,SAAgB,sBAAsB,OAAwB;AAC7D,QAAO,qBAAqB,MAAM;;AAGnC,MAAM,wBAAwB;AAE9B,SAAgB,sBAAsB,MAAuB;AAC5D,QAAO,sBAAsB,KAAK,KAAK;;AAGxC,MAAM,sBAAsB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAED,MAAM,oBAAoB;AAE1B,SAAS,eAAe,MAAuB;AAC9C,KAAI,oBAAoB,SAAS,KAAK,CAAE,QAAO;CAE/C,MAAM,cAAc,KAAK,MAAM,kBAAkB;AACjD,KAAI,YAAa,QAAO,eAAe,YAAY,GAAG;AAEtD,KAAI,KAAK,SAAS,KAAK,CAAE,QAAO,iBAAiB,KAAK;AAEtD,QAAO;;AAGR,SAAS,uBAAuB,KAAyB;AACxD,KAAI,CAAC,qBAAqB,IAAI,QAAQ,IAAI,CAAC,oBAAoB,IAAI,QAAQ,CAC1E,QAAO;AAGR,KAAI,CAAC,sBAAsB,IAAI,OAAO,IAAI,CAAC,sBAAsB,IAAI,KAAK,CACzE,QAAO;AAGR,QAAO,IAAI,WAAW,OAAO,UAAU;AACtC,MAAI,OAAO,UAAU,SACpB,QAAO,eAAe,MAAM;AAE7B,SAAO,uBAAuB,MAAM;GACnC;;AAGH,SAAgB,iB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AO,KAAK,QAAQ,SAAS,wBAAwB,GAAG,IAAI;;AAG7D,SAAgB,wBAAwB,OAAe,aAAsB,OAAe;AAC3F,QAAO,uBAAuB,OAAO,WAAW;;AAGjD,SAAS,MAAM,OAAwB;AACtC,QAAO,yBAAyB,KAAK,MAAM,IAAI,MAAM,SAAS,MAAM;;AAGrE,SAAS,iBAAiB,OAAuB;AAChD,QAAO,WAAW,KAAK,MAAM,IAAI,MAAM,SAAS,KAAK,IAAI,MAAM,SAAS"}
@@ -1,5 +1,5 @@
1
1
  import { normalizeTypeTag } from "../bcs/type-tag-serializer.mjs";
2
- import { HANEUL_ADDRESS_LENGTH, isValidHaneulAddress, isValidHaneulObjectId, isValidStructTag, isValidTransactionDigest, normalizeHaneulAddress, normalizeStructTag, normalizeSuiObjectId, parseStructTag } from "./haneul-types.mjs";
2
+ import { HANEUL_ADDRESS_LENGTH, isValidHaneulAddress, isValidHaneulObjectId, isValidStructTag, isValidTransactionDigest, normalizeHaneulAddress, normalizeHaneulObjectId, normalizeStructTag, parseStructTag } from "./haneul-types.mjs";
3
3
  import { formatAddress, formatDigest } from "./format.mjs";
4
4
  import { isValidHaneulNSName, normalizeHaneulNSName } from "./haneulns.mjs";
5
5
  import { GEUNHWA_PER_HANEUL, HANEUL_CLOCK_OBJECT_ID, HANEUL_DECIMALS, HANEUL_DENY_LIST_OBJECT_ID, HANEUL_FRAMEWORK_ADDRESS, HANEUL_RANDOM_OBJECT_ID, HANEUL_SYSTEM_ADDRESS, HANEUL_SYSTEM_MODULE_NAME, HANEUL_SYSTEM_STATE_OBJECT_ID, HANEUL_TYPE_ARG, MOVE_STDLIB_ADDRESS } from "./constants.mjs";
@@ -7,4 +7,4 @@ import { isValidNamedPackage, isValidNamedType } from "./move-registry.mjs";
7
7
  import { deriveDynamicFieldID } from "./dynamic-fields.mjs";
8
8
  import { deriveObjectID } from "./derived-objects.mjs";
9
9
  import { fromBase58, fromBase64, fromHex, toBase58, toBase64, toHex } from "@haneullabs/bcs";
10
- export { GEUNHWA_PER_HANEUL, HANEUL_ADDRESS_LENGTH, HANEUL_CLOCK_OBJECT_ID, HANEUL_DECIMALS, HANEUL_DENY_LIST_OBJECT_ID, HANEUL_FRAMEWORK_ADDRESS, HANEUL_RANDOM_OBJECT_ID, HANEUL_SYSTEM_ADDRESS, HANEUL_SYSTEM_MODULE_NAME, HANEUL_SYSTEM_STATE_OBJECT_ID, HANEUL_TYPE_ARG, MOVE_STDLIB_ADDRESS, deriveDynamicFieldID, deriveObjectID, formatAddress, formatDigest, fromBase58, fromBase64, fromHex, isValidHaneulAddress, isValidHaneulNSName, isValidHaneulObjectId, isValidNamedPackage, isValidNamedType, isValidStructTag, isValidTransactionDigest, normalizeHaneulAddress, normalizeHaneulNSName, normalizeStructTag, normalizeSuiObjectId, normalizeTypeTag, parseStructTag, toBase58, toBase64, toHex };
10
+ export { GEUNHWA_PER_HANEUL, HANEUL_ADDRESS_LENGTH, HANEUL_CLOCK_OBJECT_ID, HANEUL_DECIMALS, HANEUL_DENY_LIST_OBJECT_ID, HANEUL_FRAMEWORK_ADDRESS, HANEUL_RANDOM_OBJECT_ID, HANEUL_SYSTEM_ADDRESS, HANEUL_SYSTEM_MODULE_NAME, HANEUL_SYSTEM_STATE_OBJECT_ID, HANEUL_TYPE_ARG, MOVE_STDLIB_ADDRESS, deriveDynamicFieldID, deriveObjectID, formatAddress, formatDigest, fromBase58, fromBase64, fromHex, isValidHaneulAddress, isValidHaneulNSName, isValidHaneulObjectId, isValidNamedPackage, isValidNamedType, isValidStructTag, isValidTransactionDigest, normalizeHaneulAddress, normalizeHaneulNSName, normalizeHaneulObjectId, normalizeStructTag, normalizeTypeTag, parseStructTag, toBase58, toBase64, toHex };
@@ -1,6 +1,6 @@
1
1
  import { isValidHaneulNSName, normalizeHaneulNSName } from "./haneulns.mjs";
2
2
  import { isValidNamedPackage, isValidNamedType } from "./move-registry.mjs";
3
- import { HANEUL_ADDRESS_LENGTH, isValidHaneulAddress, isValidHaneulObjectId, isValidStructTag, isValidTransactionDigest, normalizeHaneulAddress, normalizeStructTag, normalizeSuiObjectId, parseStructTag } from "./haneul-types.mjs";
3
+ import { HANEUL_ADDRESS_LENGTH, isValidHaneulAddress, isValidHaneulObjectId, isValidStructTag, isValidTransactionDigest, normalizeHaneulAddress, normalizeHaneulObjectId, normalizeStructTag, parseStructTag } from "./haneul-types.mjs";
4
4
  import { normalizeTypeTag } from "../bcs/type-tag-serializer.mjs";
5
5
  import { deriveDynamicFieldID } from "./dynamic-fields.mjs";
6
6
  import { GEUNHWA_PER_HANEUL, HANEUL_CLOCK_OBJECT_ID, HANEUL_DECIMALS, HANEUL_DENY_LIST_OBJECT_ID, HANEUL_FRAMEWORK_ADDRESS, HANEUL_RANDOM_OBJECT_ID, HANEUL_SYSTEM_ADDRESS, HANEUL_SYSTEM_MODULE_NAME, HANEUL_SYSTEM_STATE_OBJECT_ID, HANEUL_TYPE_ARG, MOVE_STDLIB_ADDRESS } from "./constants.mjs";
@@ -8,4 +8,4 @@ import { formatAddress, formatDigest } from "./format.mjs";
8
8
  import { deriveObjectID } from "./derived-objects.mjs";
9
9
  import { fromBase58, fromBase64, fromHex, toBase58, toBase64, toHex } from "@haneullabs/bcs";
10
10
 
11
- export { GEUNHWA_PER_HANEUL, HANEUL_ADDRESS_LENGTH, HANEUL_CLOCK_OBJECT_ID, HANEUL_DECIMALS, HANEUL_DENY_LIST_OBJECT_ID, HANEUL_FRAMEWORK_ADDRESS, HANEUL_RANDOM_OBJECT_ID, HANEUL_SYSTEM_ADDRESS, HANEUL_SYSTEM_MODULE_NAME, HANEUL_SYSTEM_STATE_OBJECT_ID, HANEUL_TYPE_ARG, MOVE_STDLIB_ADDRESS, deriveDynamicFieldID, deriveObjectID, formatAddress, formatDigest, fromBase58, fromBase64, fromHex, isValidHaneulAddress, isValidHaneulNSName, isValidHaneulObjectId, isValidNamedPackage, isValidNamedType, isValidStructTag, isValidTransactionDigest, normalizeHaneulAddress, normalizeHaneulNSName, normalizeStructTag, normalizeSuiObjectId, normalizeTypeTag, parseStructTag, toBase58, toBase64, toHex };
11
+ export { GEUNHWA_PER_HANEUL, HANEUL_ADDRESS_LENGTH, HANEUL_CLOCK_OBJECT_ID, HANEUL_DECIMALS, HANEUL_DENY_LIST_OBJECT_ID, HANEUL_FRAMEWORK_ADDRESS, HANEUL_RANDOM_OBJECT_ID, HANEUL_SYSTEM_ADDRESS, HANEUL_SYSTEM_MODULE_NAME, HANEUL_SYSTEM_STATE_OBJECT_ID, HANEUL_TYPE_ARG, MOVE_STDLIB_ADDRESS, deriveDynamicFieldID, deriveObjectID, formatAddress, formatDigest, fromBase58, fromBase64, fromHex, isValidHaneulAddress, isValidHaneulNSName, isValidHaneulObjectId, isValidNamedPackage, isValidNamedType, isValidStructTag, isValidTransactionDigest, normalizeHaneulAddress, normalizeHaneulNSName, normalizeHaneulObjectId, normalizeStructTag, normalizeTypeTag, parseStructTag, toBase58, toBase64, toHex };
@@ -62,7 +62,7 @@ function publicKeyFromRawBytes(signatureScheme, bytes, options = {}) {
62
62
  break;
63
63
  default: throw new Error(`Unsupported signature scheme ${signatureScheme}`);
64
64
  }
65
- if (options.address && publicKey.toSuiAddress() !== options.address) throw new Error(`Public key bytes do not match the provided address`);
65
+ if (options.address && publicKey.toHaneulAddress() !== options.address) throw new Error(`Public key bytes do not match the provided address`);
66
66
  return publicKey;
67
67
  }
68
68
  function publicKeyFromSuiBytes(publicKey, options = {}) {
@@ -1 +1 @@
1
- {"version":3,"file":"verify.mjs","names":[],"sources":["../../src/verify/verify.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64 } from '@haneullabs/bcs';\n\nimport type { PublicKey, SignatureFlag, SignatureScheme } from '../cryptography/index.js';\nimport { parseSerializedSignature, SIGNATURE_FLAG_TO_SCHEME } from '../cryptography/index.js';\nimport { Ed25519PublicKey } from '../keypairs/ed25519/publickey.js';\nimport { PasskeyPublicKey } from '../keypairs/passkey/publickey.js';\nimport { Secp256k1PublicKey } from '../keypairs/secp256k1/publickey.js';\nimport { Secp256r1PublicKey } from '../keypairs/secp256r1/publickey.js';\nimport { MultiSigPublicKey } from '../multisig/publickey.js';\nimport { ZkLoginPublicIdentifier } from '../zklogin/publickey.js';\nimport type { ClientWithCoreApi } from '../client/core.js';\n\nexport async function verifySignature(\n\tbytes: Uint8Array,\n\tsignature: string,\n\toptions?: {\n\t\taddress?: string;\n\t},\n): Promise<PublicKey> {\n\tconst parsedSignature = parseSignature(signature);\n\n\tif (!(await parsedSignature.publicKey.verify(bytes, parsedSignature.serializedSignature))) {\n\t\tthrow new Error(`Signature is not valid for the provided data`);\n\t}\n\n\tif (options?.address && !parsedSignature.publicKey.verifyAddress(options.address)) {\n\t\tthrow new Error(`Signature is not valid for the provided address`);\n\t}\n\n\treturn parsedSignature.publicKey;\n}\n\nexport async function verifyPersonalMessageSignature(\n\tmessage: Uint8Array,\n\tsignature: string,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n): Promise<PublicKey> {\n\tconst parsedSignature = parseSignature(signature, options);\n\n\tif (\n\t\t!(await parsedSignature.publicKey.verifyPersonalMessage(\n\t\t\tmessage,\n\t\t\tparsedSignature.serializedSignature,\n\t\t))\n\t) {\n\t\tthrow new Error(`Signature is not valid for the provided message`);\n\t}\n\n\tif (options?.address && !parsedSignature.publicKey.verifyAddress(options.address)) {\n\t\tthrow new Error(`Signature is not valid for the provided address`);\n\t}\n\n\treturn parsedSignature.publicKey;\n}\n\nexport async function verifyTransactionSignature(\n\ttransaction: Uint8Array,\n\tsignature: string,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n): Promise<PublicKey> {\n\tconst parsedSignature = parseSignature(signature, options);\n\n\tif (\n\t\t!(await parsedSignature.publicKey.verifyTransaction(\n\t\t\ttransaction,\n\t\t\tparsedSignature.serializedSignature,\n\t\t))\n\t) {\n\t\tthrow new Error(`Signature is not valid for the provided Transaction`);\n\t}\n\n\tif (options?.address && !parsedSignature.publicKey.verifyAddress(options.address)) {\n\t\tthrow new Error(`Signature is not valid for the provided address`);\n\t}\n\n\treturn parsedSignature.publicKey;\n}\n\nfunction parseSignature(signature: string, options: { client?: ClientWithCoreApi } = {}) {\n\tconst parsedSignature = parseSerializedSignature(signature);\n\n\tif (parsedSignature.signatureScheme === 'MultiSig') {\n\t\treturn {\n\t\t\t...parsedSignature,\n\t\t\tpublicKey: new MultiSigPublicKey(parsedSignature.multisig.multisig_pk),\n\t\t};\n\t}\n\n\tconst publicKey = publicKeyFromRawBytes(\n\t\tparsedSignature.signatureScheme,\n\t\tparsedSignature.publicKey,\n\t\toptions,\n\t);\n\treturn {\n\t\t...parsedSignature,\n\t\tpublicKey,\n\t};\n}\n\nexport function publicKeyFromRawBytes(\n\tsignatureScheme: SignatureScheme,\n\tbytes: Uint8Array,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n): PublicKey {\n\tlet publicKey: PublicKey;\n\tswitch (signatureScheme) {\n\t\tcase 'ED25519':\n\t\t\tpublicKey = new Ed25519PublicKey(bytes);\n\t\t\tbreak;\n\t\tcase 'Secp256k1':\n\t\t\tpublicKey = new Secp256k1PublicKey(bytes);\n\t\t\tbreak;\n\t\tcase 'Secp256r1':\n\t\t\tpublicKey = new Secp256r1PublicKey(bytes);\n\t\t\tbreak;\n\t\tcase 'MultiSig':\n\t\t\tpublicKey = new MultiSigPublicKey(bytes);\n\t\t\tbreak;\n\t\tcase 'ZkLogin':\n\t\t\tpublicKey = ZkLoginPublicIdentifier.fromBytes(bytes, options);\n\t\t\tbreak;\n\t\tcase 'Passkey':\n\t\t\tpublicKey = new PasskeyPublicKey(bytes);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tthrow new Error(`Unsupported signature scheme ${signatureScheme}`);\n\t}\n\n\tif (options.address && publicKey.toSuiAddress() !== options.address) {\n\t\tthrow new Error(`Public key bytes do not match the provided address`);\n\t}\n\n\treturn publicKey;\n}\n\nexport function publicKeyFromSuiBytes(\n\tpublicKey: string | Uint8Array,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n) {\n\tconst bytes = typeof publicKey === 'string' ? fromBase64(publicKey) : publicKey;\n\n\tconst signatureScheme = SIGNATURE_FLAG_TO_SCHEME[bytes[0] as SignatureFlag];\n\n\treturn publicKeyFromRawBytes(signatureScheme, bytes.slice(1), options);\n}\n"],"mappings":";;;;;;;;;;;AAeA,eAAsB,gBACrB,OACA,WACA,SAGqB;CACrB,MAAM,kBAAkB,eAAe,UAAU;AAEjD,KAAI,CAAE,MAAM,gBAAgB,UAAU,OAAO,OAAO,gBAAgB,oBAAoB,CACvF,OAAM,IAAI,MAAM,+CAA+C;AAGhE,KAAI,SAAS,WAAW,CAAC,gBAAgB,UAAU,cAAc,QAAQ,QAAQ,CAChF,OAAM,IAAI,MAAM,kDAAkD;AAGnE,QAAO,gBAAgB;;AAGxB,eAAsB,+BACrB,SACA,WACA,UAA4D,EAAE,EACzC;CACrB,MAAM,kBAAkB,eAAe,WAAW,QAAQ;AAE1D,KACC,CAAE,MAAM,gBAAgB,UAAU,sBACjC,SACA,gBAAgB,oBAChB,CAED,OAAM,IAAI,MAAM,kDAAkD;AAGnE,KAAI,SAAS,WAAW,CAAC,gBAAgB,UAAU,cAAc,QAAQ,QAAQ,CAChF,OAAM,IAAI,MAAM,kDAAkD;AAGnE,QAAO,gBAAgB;;AAGxB,eAAsB,2BACrB,aACA,WACA,UAA4D,EAAE,EACzC;CACrB,MAAM,kBAAkB,eAAe,WAAW,QAAQ;AAE1D,KACC,CAAE,MAAM,gBAAgB,UAAU,kBACjC,aACA,gBAAgB,oBAChB,CAED,OAAM,IAAI,MAAM,sDAAsD;AAGvE,KAAI,SAAS,WAAW,CAAC,gBAAgB,UAAU,cAAc,QAAQ,QAAQ,CAChF,OAAM,IAAI,MAAM,kDAAkD;AAGnE,QAAO,gBAAgB;;AAGxB,SAAS,eAAe,WAAmB,UAA0C,EAAE,EAAE;CACxF,MAAM,kBAAkB,yBAAyB,UAAU;AAE3D,KAAI,gBAAgB,oBAAoB,WACvC,QAAO;EACN,GAAG;EACH,WAAW,IAAI,kBAAkB,gBAAgB,SAAS,YAAY;EACtE;CAGF,MAAM,YAAY,sBACjB,gBAAgB,iBAChB,gBAAgB,WAChB,QACA;AACD,QAAO;EACN,GAAG;EACH;EACA;;AAGF,SAAgB,sBACf,iBACA,OACA,UAA4D,EAAE,EAClD;CACZ,IAAI;AACJ,SAAQ,iBAAR;EACC,KAAK;AACJ,eAAY,IAAI,iBAAiB,MAAM;AACvC;EACD,KAAK;AACJ,eAAY,IAAI,mBAAmB,MAAM;AACzC;EACD,KAAK;AACJ,eAAY,IAAI,mBAAmB,MAAM;AACzC;EACD,KAAK;AACJ,eAAY,IAAI,kBAAkB,MAAM;AACxC;EACD,KAAK;AACJ,eAAY,wBAAwB,UAAU,OAAO,QAAQ;AAC7D;EACD,KAAK;AACJ,eAAY,IAAI,iBAAiB,MAAM;AACvC;EACD,QACC,OAAM,IAAI,MAAM,gCAAgC,kBAAkB;;AAGpE,KAAI,QAAQ,WAAW,UAAU,cAAc,KAAK,QAAQ,QAC3D,OAAM,IAAI,MAAM,qDAAqD;AAGtE,QAAO;;AAGR,SAAgB,sBACf,WACA,UAA4D,EAAE,EAC7D;CACD,MAAM,QAAQ,OAAO,cAAc,WAAW,WAAW,UAAU,GAAG;CAEtE,MAAM,kBAAkB,yBAAyB,MAAM;AAEvD,QAAO,sBAAsB,iBAAiB,MAAM,MAAM,EAAE,EAAE,QAAQ"}
1
+ {"version":3,"file":"verify.mjs","names":[],"sources":["../../src/verify/verify.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64 } from '@haneullabs/bcs';\n\nimport type { PublicKey, SignatureFlag, SignatureScheme } from '../cryptography/index.js';\nimport { parseSerializedSignature, SIGNATURE_FLAG_TO_SCHEME } from '../cryptography/index.js';\nimport { Ed25519PublicKey } from '../keypairs/ed25519/publickey.js';\nimport { PasskeyPublicKey } from '../keypairs/passkey/publickey.js';\nimport { Secp256k1PublicKey } from '../keypairs/secp256k1/publickey.js';\nimport { Secp256r1PublicKey } from '../keypairs/secp256r1/publickey.js';\nimport { MultiSigPublicKey } from '../multisig/publickey.js';\nimport { ZkLoginPublicIdentifier } from '../zklogin/publickey.js';\nimport type { ClientWithCoreApi } from '../client/core.js';\n\nexport async function verifySignature(\n\tbytes: Uint8Array,\n\tsignature: string,\n\toptions?: {\n\t\taddress?: string;\n\t},\n): Promise<PublicKey> {\n\tconst parsedSignature = parseSignature(signature);\n\n\tif (!(await parsedSignature.publicKey.verify(bytes, parsedSignature.serializedSignature))) {\n\t\tthrow new Error(`Signature is not valid for the provided data`);\n\t}\n\n\tif (options?.address && !parsedSignature.publicKey.verifyAddress(options.address)) {\n\t\tthrow new Error(`Signature is not valid for the provided address`);\n\t}\n\n\treturn parsedSignature.publicKey;\n}\n\nexport async function verifyPersonalMessageSignature(\n\tmessage: Uint8Array,\n\tsignature: string,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n): Promise<PublicKey> {\n\tconst parsedSignature = parseSignature(signature, options);\n\n\tif (\n\t\t!(await parsedSignature.publicKey.verifyPersonalMessage(\n\t\t\tmessage,\n\t\t\tparsedSignature.serializedSignature,\n\t\t))\n\t) {\n\t\tthrow new Error(`Signature is not valid for the provided message`);\n\t}\n\n\tif (options?.address && !parsedSignature.publicKey.verifyAddress(options.address)) {\n\t\tthrow new Error(`Signature is not valid for the provided address`);\n\t}\n\n\treturn parsedSignature.publicKey;\n}\n\nexport async function verifyTransactionSignature(\n\ttransaction: Uint8Array,\n\tsignature: string,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n): Promise<PublicKey> {\n\tconst parsedSignature = parseSignature(signature, options);\n\n\tif (\n\t\t!(await parsedSignature.publicKey.verifyTransaction(\n\t\t\ttransaction,\n\t\t\tparsedSignature.serializedSignature,\n\t\t))\n\t) {\n\t\tthrow new Error(`Signature is not valid for the provided Transaction`);\n\t}\n\n\tif (options?.address && !parsedSignature.publicKey.verifyAddress(options.address)) {\n\t\tthrow new Error(`Signature is not valid for the provided address`);\n\t}\n\n\treturn parsedSignature.publicKey;\n}\n\nfunction parseSignature(signature: string, options: { client?: ClientWithCoreApi } = {}) {\n\tconst parsedSignature = parseSerializedSignature(signature);\n\n\tif (parsedSignature.signatureScheme === 'MultiSig') {\n\t\treturn {\n\t\t\t...parsedSignature,\n\t\t\tpublicKey: new MultiSigPublicKey(parsedSignature.multisig.multisig_pk),\n\t\t};\n\t}\n\n\tconst publicKey = publicKeyFromRawBytes(\n\t\tparsedSignature.signatureScheme,\n\t\tparsedSignature.publicKey,\n\t\toptions,\n\t);\n\treturn {\n\t\t...parsedSignature,\n\t\tpublicKey,\n\t};\n}\n\nexport function publicKeyFromRawBytes(\n\tsignatureScheme: SignatureScheme,\n\tbytes: Uint8Array,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n): PublicKey {\n\tlet publicKey: PublicKey;\n\tswitch (signatureScheme) {\n\t\tcase 'ED25519':\n\t\t\tpublicKey = new Ed25519PublicKey(bytes);\n\t\t\tbreak;\n\t\tcase 'Secp256k1':\n\t\t\tpublicKey = new Secp256k1PublicKey(bytes);\n\t\t\tbreak;\n\t\tcase 'Secp256r1':\n\t\t\tpublicKey = new Secp256r1PublicKey(bytes);\n\t\t\tbreak;\n\t\tcase 'MultiSig':\n\t\t\tpublicKey = new MultiSigPublicKey(bytes);\n\t\t\tbreak;\n\t\tcase 'ZkLogin':\n\t\t\tpublicKey = ZkLoginPublicIdentifier.fromBytes(bytes, options);\n\t\t\tbreak;\n\t\tcase 'Passkey':\n\t\t\tpublicKey = new PasskeyPublicKey(bytes);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tthrow new Error(`Unsupported signature scheme ${signatureScheme}`);\n\t}\n\n\tif (options.address && publicKey.toHaneulAddress() !== options.address) {\n\t\tthrow new Error(`Public key bytes do not match the provided address`);\n\t}\n\n\treturn publicKey;\n}\n\nexport function publicKeyFromSuiBytes(\n\tpublicKey: string | Uint8Array,\n\toptions: { client?: ClientWithCoreApi; address?: string } = {},\n) {\n\tconst bytes = typeof publicKey === 'string' ? fromBase64(publicKey) : publicKey;\n\n\tconst signatureScheme = SIGNATURE_FLAG_TO_SCHEME[bytes[0] as SignatureFlag];\n\n\treturn publicKeyFromRawBytes(signatureScheme, bytes.slice(1), options);\n}\n"],"mappings":";;;;;;;;;;;AAeA,eAAsB,gBACrB,OACA,WACA,SAGqB;CACrB,MAAM,kBAAkB,eAAe,UAAU;AAEjD,KAAI,CAAE,MAAM,gBAAgB,UAAU,OAAO,OAAO,gBAAgB,oBAAoB,CACvF,OAAM,IAAI,MAAM,+CAA+C;AAGhE,KAAI,SAAS,WAAW,CAAC,gBAAgB,UAAU,cAAc,QAAQ,QAAQ,CAChF,OAAM,IAAI,MAAM,kDAAkD;AAGnE,QAAO,gBAAgB;;AAGxB,eAAsB,+BACrB,SACA,WACA,UAA4D,EAAE,EACzC;CACrB,MAAM,kBAAkB,eAAe,WAAW,QAAQ;AAE1D,KACC,CAAE,MAAM,gBAAgB,UAAU,sBACjC,SACA,gBAAgB,oBAChB,CAED,OAAM,IAAI,MAAM,kDAAkD;AAGnE,KAAI,SAAS,WAAW,CAAC,gBAAgB,UAAU,cAAc,QAAQ,QAAQ,CAChF,OAAM,IAAI,MAAM,kDAAkD;AAGnE,QAAO,gBAAgB;;AAGxB,eAAsB,2BACrB,aACA,WACA,UAA4D,EAAE,EACzC;CACrB,MAAM,kBAAkB,eAAe,WAAW,QAAQ;AAE1D,KACC,CAAE,MAAM,gBAAgB,UAAU,kBACjC,aACA,gBAAgB,oBAChB,CAED,OAAM,IAAI,MAAM,sDAAsD;AAGvE,KAAI,SAAS,WAAW,CAAC,gBAAgB,UAAU,cAAc,QAAQ,QAAQ,CAChF,OAAM,IAAI,MAAM,kDAAkD;AAGnE,QAAO,gBAAgB;;AAGxB,SAAS,eAAe,WAAmB,UAA0C,EAAE,EAAE;CACxF,MAAM,kBAAkB,yBAAyB,UAAU;AAE3D,KAAI,gBAAgB,oBAAoB,WACvC,QAAO;EACN,GAAG;EACH,WAAW,IAAI,kBAAkB,gBAAgB,SAAS,YAAY;EACtE;CAGF,MAAM,YAAY,sBACjB,gBAAgB,iBAChB,gBAAgB,WAChB,QACA;AACD,QAAO;EACN,GAAG;EACH;EACA;;AAGF,SAAgB,sBACf,iBACA,OACA,UAA4D,EAAE,EAClD;CACZ,IAAI;AACJ,SAAQ,iBAAR;EACC,KAAK;AACJ,eAAY,IAAI,iBAAiB,MAAM;AACvC;EACD,KAAK;AACJ,eAAY,IAAI,mBAAmB,MAAM;AACzC;EACD,KAAK;AACJ,eAAY,IAAI,mBAAmB,MAAM;AACzC;EACD,KAAK;AACJ,eAAY,IAAI,kBAAkB,MAAM;AACxC;EACD,KAAK;AACJ,eAAY,wBAAwB,UAAU,OAAO,QAAQ;AAC7D;EACD,KAAK;AACJ,eAAY,IAAI,iBAAiB,MAAM;AACvC;EACD,QACC,OAAM,IAAI,MAAM,gCAAgC,kBAAkB;;AAGpE,KAAI,QAAQ,WAAW,UAAU,iBAAiB,KAAK,QAAQ,QAC9D,OAAM,IAAI,MAAM,qDAAqD;AAGtE,QAAO;;AAGR,SAAgB,sBACf,WACA,UAA4D,EAAE,EAC7D;CACD,MAAM,QAAQ,OAAO,cAAc,WAAW,WAAW,UAAU,GAAG;CAEtE,MAAM,kBAAkB,yBAAyB,MAAM;AAEvD,QAAO,sBAAsB,iBAAiB,MAAM,MAAM,EAAE,EAAE,QAAQ"}
package/dist/version.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region src/version.ts
2
- const PACKAGE_VERSION = "2.4.0";
2
+ const PACKAGE_VERSION = "2.5.1";
3
3
  const TARGETED_RPC_VERSION = "1.0.0";
4
4
 
5
5
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This file is generated by genversion.mjs. Do not edit it directly.\n\nexport const PACKAGE_VERSION = '2.4.0';\nexport const TARGETED_RPC_VERSION = '1.0.0';\n"],"mappings":";AAKA,MAAa,kBAAkB;AAC/B,MAAa,uBAAuB"}
1
+ {"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This file is generated by genversion.mjs. Do not edit it directly.\n\nexport const PACKAGE_VERSION = '2.5.1';\nexport const TARGETED_RPC_VERSION = '1.0.0';\n"],"mappings":";AAKA,MAAa,kBAAkB;AAC/B,MAAa,uBAAuB"}
@@ -1,31 +1,31 @@
1
- import * as _haneullabs_bcs810 from "@haneullabs/bcs";
1
+ import * as _haneullabs_bcs1111 from "@haneullabs/bcs";
2
2
  import { InferBcsInput } from "@haneullabs/bcs";
3
3
 
4
4
  //#region src/zklogin/bcs.d.ts
5
- declare const zkLoginSignature: _haneullabs_bcs810.BcsStruct<{
6
- inputs: _haneullabs_bcs810.BcsStruct<{
7
- proofPoints: _haneullabs_bcs810.BcsStruct<{
8
- a: _haneullabs_bcs810.BcsType<string[], Iterable<string> & {
5
+ declare const zkLoginSignature: _haneullabs_bcs1111.BcsStruct<{
6
+ inputs: _haneullabs_bcs1111.BcsStruct<{
7
+ proofPoints: _haneullabs_bcs1111.BcsStruct<{
8
+ a: _haneullabs_bcs1111.BcsType<string[], Iterable<string> & {
9
9
  length: number;
10
10
  }, string>;
11
- b: _haneullabs_bcs810.BcsType<string[][], Iterable<Iterable<string> & {
11
+ b: _haneullabs_bcs1111.BcsType<string[][], Iterable<Iterable<string> & {
12
12
  length: number;
13
13
  }> & {
14
14
  length: number;
15
15
  }, string>;
16
- c: _haneullabs_bcs810.BcsType<string[], Iterable<string> & {
16
+ c: _haneullabs_bcs1111.BcsType<string[], Iterable<string> & {
17
17
  length: number;
18
18
  }, string>;
19
19
  }, string>;
20
- issBase64Details: _haneullabs_bcs810.BcsStruct<{
21
- value: _haneullabs_bcs810.BcsType<string, string, "string">;
22
- indexMod4: _haneullabs_bcs810.BcsType<number, number, "u8">;
20
+ issBase64Details: _haneullabs_bcs1111.BcsStruct<{
21
+ value: _haneullabs_bcs1111.BcsType<string, string, "string">;
22
+ indexMod4: _haneullabs_bcs1111.BcsType<number, number, "u8">;
23
23
  }, string>;
24
- headerBase64: _haneullabs_bcs810.BcsType<string, string, "string">;
25
- addressSeed: _haneullabs_bcs810.BcsType<string, string, "string">;
24
+ headerBase64: _haneullabs_bcs1111.BcsType<string, string, "string">;
25
+ addressSeed: _haneullabs_bcs1111.BcsType<string, string, "string">;
26
26
  }, string>;
27
- maxEpoch: _haneullabs_bcs810.BcsType<string, string | number | bigint, "u64">;
28
- userSignature: _haneullabs_bcs810.BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "vector<u8>">;
27
+ maxEpoch: _haneullabs_bcs1111.BcsType<string, string | number | bigint, "u64">;
28
+ userSignature: _haneullabs_bcs1111.BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "vector<u8>">;
29
29
  }, string>;
30
30
  type ZkLoginSignature = InferBcsInput<typeof zkLoginSignature>;
31
31
  type ZkLoginSignatureInputs = ZkLoginSignature['inputs'];
@@ -1 +1 @@
1
- {"version":3,"file":"bcs.d.mts","names":[],"sources":["../../src/zklogin/bcs.ts"],"sourcesContent":[],"mappings":";;;;cAMa,qCAAgB;;;MAAhB,CAAA,4BAgBX,CAAA,MAAA,EAAA,UAAA,CAAA,MAAA,CAAA,GAAA;;;;;;;;;;;;;;;;;;;;2CAhB2B,WAAA,gBAAA,CAAA,UAAA,CAAA,MAAA,CAAA,EAAA,YAAA,CAAA;CAAA,EAAA,MAAA,CAAA;AAkBjB,KAAA,gBAAA,GAAmB,aAAqB,CAAA,OAAA,gBAAR,CAAA;AAChC,KAAA,sBAAA,GAAyB,gBAAA,CAAA,QAAgB,CAAA"}
1
+ {"version":3,"file":"bcs.d.mts","names":[],"sources":["../../src/zklogin/bcs.ts"],"sourcesContent":[],"mappings":";;;;cAMa,sCAAgB;;;MAAhB,CAAA,6BAgBX,CAAA,MAAA,EAAA,UAAA,CAAA,MAAA,CAAA,GAAA;;;;;;;;;;;;;;;;;;;;4CAhB2B,WAAA,gBAAA,CAAA,UAAA,CAAA,MAAA,CAAA,EAAA,YAAA,CAAA;CAAA,EAAA,MAAA,CAAA;AAkBjB,KAAA,gBAAA,GAAmB,aAAqB,CAAA,OAAA,gBAAR,CAAA;AAChC,KAAA,sBAAA,GAAyB,gBAAA,CAAA,QAAgB,CAAA"}
@@ -32,7 +32,7 @@ declare class ZkLoginPublicIdentifier extends PublicKey {
32
32
  * Checks if two zkLogin public identifiers are equal
33
33
  */
34
34
  equals(publicKey: ZkLoginPublicIdentifier): boolean;
35
- toSuiAddress(): string;
35
+ toHaneulAddress(): string;
36
36
  /**
37
37
  * Return the byte array representation of the zkLogin public identifier
38
38
  */
@@ -1 +1 @@
1
- {"version":3,"file":"publickey.d.mts","names":[],"sources":["../../src/zklogin/publickey.ts"],"sourcesContent":[],"mappings":";;;;;;;AAoBA;;AASyC,cAT5B,uBAAA,SAAgC,SAAA,CASJ;EAAqB,CAAA,OAAA;EAoBrD;;;;EAKO,WAAA,CAAA,KAAA,EAzBI,iBAyBJ,EAAA;IAAA;EAmC0B,CAAA,CAnC1B,EAAA;IAAmE,MAAA,CAAA,EAzBrB,iBAyBqB;EAmCzC,CAAA;EAAsB,OAAA,SAAA,CAAA,KAAA,EAxCvD,UAwCuD,EAAA;IAAA,MAAA;IAAA,OAAA;IAAA;EAiExC,CAAA,CAjEwC,EAAA;IA0BpC,MAAA,CAAA,EA7DZ,iBA6DY;IAyBF,OAAA,CAAA,EAAA,MAAA;IAAX,aAAA,CAAA,EAAA,OAAA;EAcS,CAAA,CAAA,EApG2D,uBAoG3D;EAAwB,OAAA,SAAA,CAAA,OAAA,EAAA,MAAA,EAAA,KAAA,EAjEN,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BAAuB,sBAAsB;;;;iCAgB7C,uBAAuB,sBAAsB;;;;;;iBAqB7D,yBAAA;WAGK;;IAClB"}
@@ -35,18 +35,18 @@ var ZkLoginPublicIdentifier = class ZkLoginPublicIdentifier extends PublicKey {
35
35
  else if (legacyAddress === false) publicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, false), { client });
36
36
  else if (address) {
37
37
  publicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, false), { client });
38
- if (publicKey.toSuiAddress() !== address) publicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, true), { client });
38
+ if (publicKey.toHaneulAddress() !== address) publicKey = new ZkLoginPublicIdentifier(normalizeZkLoginPublicKeyBytes(bytes, true), { client });
39
39
  } else publicKey = new ZkLoginPublicIdentifier(bytes, { client });
40
- if (address && publicKey.toSuiAddress() !== address) throw new Error("Public key bytes do not match the provided address");
40
+ if (address && publicKey.toHaneulAddress() !== address) throw new Error("Public key bytes do not match the provided address");
41
41
  return publicKey;
42
42
  }
43
43
  static fromProof(address, proof) {
44
44
  const { issBase64Details, addressSeed } = proof;
45
45
  const iss = extractClaimValue(issBase64Details, "iss");
46
46
  const legacyPublicKey = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, { legacyAddress: true });
47
- if (legacyPublicKey.toSuiAddress() === address) return legacyPublicKey;
47
+ if (legacyPublicKey.toHaneulAddress() === address) return legacyPublicKey;
48
48
  const publicKey = toZkLoginPublicIdentifier(BigInt(addressSeed), iss, { legacyAddress: false });
49
- if (publicKey.toSuiAddress() !== address) throw new Error("Proof does not match address");
49
+ if (publicKey.toHaneulAddress() !== address) throw new Error("Proof does not match address");
50
50
  return publicKey;
51
51
  }
52
52
  /**
@@ -55,9 +55,9 @@ var ZkLoginPublicIdentifier = class ZkLoginPublicIdentifier extends PublicKey {
55
55
  equals(publicKey) {
56
56
  return super.equals(publicKey);
57
57
  }
58
- toSuiAddress() {
58
+ toHaneulAddress() {
59
59
  if (this.#legacyAddress) return this.#toLegacyAddress();
60
- return super.toSuiAddress();
60
+ return super.toHaneulAddress();
61
61
  }
62
62
  #toLegacyAddress() {
63
63
  const legacyBytes = normalizeZkLoginPublicKeyBytes(this.#data, true);
@@ -90,7 +90,7 @@ var ZkLoginPublicIdentifier = class ZkLoginPublicIdentifier extends PublicKey {
90
90
  verifyPersonalMessage(message, signature) {
91
91
  const parsedSignature = parseSerializedZkLoginSignature(signature);
92
92
  return graphqlVerifyZkLoginSignature({
93
- address: new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress(),
93
+ address: new ZkLoginPublicIdentifier(parsedSignature.publicKey).toHaneulAddress(),
94
94
  bytes: toBase64(message),
95
95
  signature: parsedSignature.serializedSignature,
96
96
  intentScope: "PersonalMessage",
@@ -103,7 +103,7 @@ var ZkLoginPublicIdentifier = class ZkLoginPublicIdentifier extends PublicKey {
103
103
  verifyTransaction(transaction, signature) {
104
104
  const parsedSignature = parseSerializedZkLoginSignature(signature);
105
105
  return graphqlVerifyZkLoginSignature({
106
- address: new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress(),
106
+ address: new ZkLoginPublicIdentifier(parsedSignature.publicKey).toHaneulAddress(),
107
107
  bytes: toBase64(transaction),
108
108
  signature: parsedSignature.serializedSignature,
109
109
  intentScope: "TransactionData",
@@ -114,7 +114,7 @@ var ZkLoginPublicIdentifier = class ZkLoginPublicIdentifier extends PublicKey {
114
114
  * Verifies that the public key is associated with the provided address
115
115
  */
116
116
  verifyAddress(address) {
117
- return address === super.toSuiAddress() || address === this.#toLegacyAddress();
117
+ return address === super.toHaneulAddress() || address === this.#toLegacyAddress();
118
118
  }
119
119
  };
120
120
  function toZkLoginPublicIdentifier(addressSeed, iss, options) {