@mysten/signers 0.6.2 → 1.0.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 (118) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +5 -2
  3. package/dist/aws/aws-client.d.mts +48 -0
  4. package/dist/aws/aws-client.d.mts.map +1 -0
  5. package/dist/aws/aws-client.mjs +46 -0
  6. package/dist/aws/aws-client.mjs.map +1 -0
  7. package/dist/aws/aws-kms-signer.d.mts +63 -0
  8. package/dist/aws/aws-kms-signer.d.mts.map +1 -0
  9. package/dist/aws/aws-kms-signer.mjs +78 -0
  10. package/dist/aws/aws-kms-signer.mjs.map +1 -0
  11. package/dist/aws/aws4fetch.d.mts +62 -0
  12. package/dist/aws/aws4fetch.d.mts.map +1 -0
  13. package/dist/aws/aws4fetch.mjs +313 -0
  14. package/dist/aws/aws4fetch.mjs.map +1 -0
  15. package/dist/aws/index.d.mts +3 -0
  16. package/dist/aws/index.mjs +3 -0
  17. package/dist/gcp/gcp-kms-client.d.mts +71 -0
  18. package/dist/gcp/gcp-kms-client.d.mts.map +1 -0
  19. package/dist/gcp/gcp-kms-client.mjs +104 -0
  20. package/dist/gcp/gcp-kms-client.mjs.map +1 -0
  21. package/dist/gcp/index.d.mts +2 -0
  22. package/dist/gcp/index.mjs +3 -0
  23. package/dist/ledger/index.d.mts +74 -0
  24. package/dist/ledger/index.d.mts.map +1 -0
  25. package/dist/ledger/index.mjs +110 -0
  26. package/dist/ledger/index.mjs.map +1 -0
  27. package/dist/ledger/objects.d.mts +10 -0
  28. package/dist/ledger/objects.d.mts.map +1 -0
  29. package/dist/ledger/objects.mjs +16 -0
  30. package/dist/ledger/objects.mjs.map +1 -0
  31. package/dist/utils/utils.mjs +71 -0
  32. package/dist/utils/utils.mjs.map +1 -0
  33. package/dist/webcrypto/index.d.mts +32 -0
  34. package/dist/webcrypto/index.d.mts.map +1 -0
  35. package/dist/webcrypto/index.mjs +70 -0
  36. package/dist/webcrypto/index.mjs.map +1 -0
  37. package/package.json +34 -28
  38. package/src/aws/aws-kms-signer.ts +0 -9
  39. package/src/gcp/gcp-kms-client.ts +0 -9
  40. package/src/ledger/index.ts +4 -5
  41. package/src/ledger/objects.ts +10 -34
  42. package/src/utils/utils.ts +18 -10
  43. package/src/webcrypto/index.ts +6 -3
  44. package/aws/package.json +0 -6
  45. package/dist/cjs/aws/aws-client.d.ts +0 -43
  46. package/dist/cjs/aws/aws-client.js +0 -79
  47. package/dist/cjs/aws/aws-client.js.map +0 -7
  48. package/dist/cjs/aws/aws-kms-signer.d.ts +0 -61
  49. package/dist/cjs/aws/aws-kms-signer.js +0 -114
  50. package/dist/cjs/aws/aws-kms-signer.js.map +0 -7
  51. package/dist/cjs/aws/aws4fetch.d.ts +0 -125
  52. package/dist/cjs/aws/aws4fetch.js +0 -382
  53. package/dist/cjs/aws/aws4fetch.js.map +0 -7
  54. package/dist/cjs/aws/index.d.ts +0 -5
  55. package/dist/cjs/aws/index.js +0 -25
  56. package/dist/cjs/aws/index.js.map +0 -7
  57. package/dist/cjs/gcp/gcp-kms-client.d.ts +0 -68
  58. package/dist/cjs/gcp/gcp-kms-client.js +0 -147
  59. package/dist/cjs/gcp/gcp-kms-client.js.map +0 -7
  60. package/dist/cjs/gcp/index.d.ts +0 -4
  61. package/dist/cjs/gcp/index.js +0 -25
  62. package/dist/cjs/gcp/index.js.map +0 -7
  63. package/dist/cjs/ledger/bcs.d.ts +0 -14
  64. package/dist/cjs/ledger/bcs.js +0 -85
  65. package/dist/cjs/ledger/bcs.js.map +0 -7
  66. package/dist/cjs/ledger/index.d.ts +0 -66
  67. package/dist/cjs/ledger/index.js +0 -158
  68. package/dist/cjs/ledger/index.js.map +0 -7
  69. package/dist/cjs/ledger/objects.d.ts +0 -5
  70. package/dist/cjs/ledger/objects.js +0 -60
  71. package/dist/cjs/ledger/objects.js.map +0 -7
  72. package/dist/cjs/package.json +0 -5
  73. package/dist/cjs/utils/utils.d.ts +0 -18
  74. package/dist/cjs/utils/utils.js +0 -85
  75. package/dist/cjs/utils/utils.js.map +0 -7
  76. package/dist/cjs/webcrypto/index.d.ts +0 -26
  77. package/dist/cjs/webcrypto/index.js +0 -112
  78. package/dist/cjs/webcrypto/index.js.map +0 -7
  79. package/dist/esm/aws/aws-client.d.ts +0 -43
  80. package/dist/esm/aws/aws-client.js +0 -59
  81. package/dist/esm/aws/aws-client.js.map +0 -7
  82. package/dist/esm/aws/aws-kms-signer.d.ts +0 -61
  83. package/dist/esm/aws/aws-kms-signer.js +0 -94
  84. package/dist/esm/aws/aws-kms-signer.js.map +0 -7
  85. package/dist/esm/aws/aws4fetch.d.ts +0 -125
  86. package/dist/esm/aws/aws4fetch.js +0 -362
  87. package/dist/esm/aws/aws4fetch.js.map +0 -7
  88. package/dist/esm/aws/index.d.ts +0 -5
  89. package/dist/esm/aws/index.js +0 -5
  90. package/dist/esm/aws/index.js.map +0 -7
  91. package/dist/esm/gcp/gcp-kms-client.d.ts +0 -68
  92. package/dist/esm/gcp/gcp-kms-client.js +0 -127
  93. package/dist/esm/gcp/gcp-kms-client.js.map +0 -7
  94. package/dist/esm/gcp/index.d.ts +0 -4
  95. package/dist/esm/gcp/index.js +0 -5
  96. package/dist/esm/gcp/index.js.map +0 -7
  97. package/dist/esm/ledger/bcs.d.ts +0 -14
  98. package/dist/esm/ledger/bcs.js +0 -70
  99. package/dist/esm/ledger/bcs.js.map +0 -7
  100. package/dist/esm/ledger/index.d.ts +0 -66
  101. package/dist/esm/ledger/index.js +0 -138
  102. package/dist/esm/ledger/index.js.map +0 -7
  103. package/dist/esm/ledger/objects.d.ts +0 -5
  104. package/dist/esm/ledger/objects.js +0 -40
  105. package/dist/esm/ledger/objects.js.map +0 -7
  106. package/dist/esm/package.json +0 -5
  107. package/dist/esm/utils/utils.d.ts +0 -18
  108. package/dist/esm/utils/utils.js +0 -65
  109. package/dist/esm/utils/utils.js.map +0 -7
  110. package/dist/esm/webcrypto/index.d.ts +0 -26
  111. package/dist/esm/webcrypto/index.js +0 -92
  112. package/dist/esm/webcrypto/index.js.map +0 -7
  113. package/dist/tsconfig.esm.tsbuildinfo +0 -1
  114. package/dist/tsconfig.tsbuildinfo +0 -1
  115. package/gcp/package.json +0 -6
  116. package/ledger/package.json +0 -6
  117. package/src/ledger/bcs.ts +0 -87
  118. package/webcrypto/package.json +0 -6
@@ -0,0 +1,110 @@
1
+ import { getInputObjects } from "./objects.mjs";
2
+ import { Signer, messageWithIntent, toSerializedSignature } from "@mysten/sui/cryptography";
3
+ import { toBase64 } from "@mysten/sui/utils";
4
+ import { Ed25519PublicKey } from "@mysten/sui/keypairs/ed25519";
5
+ import { Transaction } from "@mysten/sui/transactions";
6
+ import { bcs } from "@mysten/sui/bcs";
7
+
8
+ //#region src/ledger/index.ts
9
+ /**
10
+ * Ledger integrates with the Sui blockchain to provide signing capabilities using Ledger devices.
11
+ */
12
+ var LedgerSigner = class LedgerSigner extends Signer {
13
+ #derivationPath;
14
+ #publicKey;
15
+ #ledgerClient;
16
+ #suiClient;
17
+ /**
18
+ * Creates an instance of LedgerSigner. It's expected to call the static `fromDerivationPath` method to create an instance.
19
+ * @example
20
+ * ```
21
+ * const signer = await LedgerSigner.fromDerivationPath(derivationPath, options);
22
+ * ```
23
+ */
24
+ constructor({ publicKey, derivationPath, ledgerClient, suiClient }) {
25
+ super();
26
+ this.#publicKey = publicKey;
27
+ this.#derivationPath = derivationPath;
28
+ this.#ledgerClient = ledgerClient;
29
+ this.#suiClient = suiClient;
30
+ }
31
+ /**
32
+ * Retrieves the key scheme used by this signer.
33
+ */
34
+ getKeyScheme() {
35
+ return "ED25519";
36
+ }
37
+ /**
38
+ * Retrieves the public key associated with this signer.
39
+ * @returns The Ed25519PublicKey instance.
40
+ */
41
+ getPublicKey() {
42
+ return this.#publicKey;
43
+ }
44
+ /**
45
+ * Signs the provided transaction bytes.
46
+ * @returns The signed transaction bytes and signature.
47
+ */
48
+ async signTransaction(bytes, bcsObjects, resolution) {
49
+ const transactionOptions = bcsObjects ? { bcsObjects } : await getInputObjects(Transaction.from(bytes), this.#suiClient).catch(() => ({ bcsObjects: [] }));
50
+ const intentMessage = messageWithIntent("TransactionData", bytes);
51
+ const { signature } = await this.#ledgerClient.signTransaction(this.#derivationPath, intentMessage, transactionOptions, resolution);
52
+ return {
53
+ bytes: toBase64(bytes),
54
+ signature: toSerializedSignature({
55
+ signature,
56
+ signatureScheme: this.getKeyScheme(),
57
+ publicKey: this.#publicKey
58
+ })
59
+ };
60
+ }
61
+ /**
62
+ * Signs the provided personal message.
63
+ * @returns The signed message bytes and signature.
64
+ */
65
+ async signPersonalMessage(bytes) {
66
+ const intentMessage = messageWithIntent("PersonalMessage", bcs.byteVector().serialize(bytes).toBytes());
67
+ const { signature } = await this.#ledgerClient.signTransaction(this.#derivationPath, intentMessage);
68
+ return {
69
+ bytes: toBase64(bytes),
70
+ signature: toSerializedSignature({
71
+ signature,
72
+ signatureScheme: this.getKeyScheme(),
73
+ publicKey: this.#publicKey
74
+ })
75
+ };
76
+ }
77
+ /**
78
+ * Prepares the signer by fetching and setting the public key from a Ledger device.
79
+ * It is recommended to initialize an `LedgerSigner` instance using this function.
80
+ * @returns A promise that resolves once a `LedgerSigner` instance is prepared (public key is set).
81
+ */
82
+ static async fromDerivationPath(derivationPath, ledgerClient, suiClient) {
83
+ const { publicKey } = await ledgerClient.getPublicKey(derivationPath);
84
+ if (!publicKey) throw new Error("Failed to get public key from Ledger.");
85
+ return new LedgerSigner({
86
+ derivationPath,
87
+ publicKey: new Ed25519PublicKey(publicKey),
88
+ ledgerClient,
89
+ suiClient
90
+ });
91
+ }
92
+ /**
93
+ * Generic signing is not supported by Ledger.
94
+ * @throws Always throws an error indicating generic signing is unsupported.
95
+ */
96
+ sign() {
97
+ throw new Error("Ledger Signer does not support generic signing.");
98
+ }
99
+ /**
100
+ * Generic signing is not supported by Ledger.
101
+ * @throws Always throws an error indicating generic signing is unsupported.
102
+ */
103
+ signWithIntent() {
104
+ throw new Error("Ledger Signer does not support generic signing.");
105
+ }
106
+ };
107
+
108
+ //#endregion
109
+ export { LedgerSigner, getInputObjects };
110
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["#publicKey","#derivationPath","#ledgerClient","#suiClient"],"sources":["../../src/ledger/index.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type SuiLedgerClient from '@mysten/ledgerjs-hw-app-sui';\nimport type { ClientWithCoreApi } from '@mysten/sui/client';\nimport type { SignatureWithBytes } from '@mysten/sui/cryptography';\nimport { messageWithIntent, Signer, toSerializedSignature } from '@mysten/sui/cryptography';\nimport { Ed25519PublicKey } from '@mysten/sui/keypairs/ed25519';\nimport { Transaction } from '@mysten/sui/transactions';\nimport { toBase64 } from '@mysten/sui/utils';\n\nimport { bcs } from '@mysten/sui/bcs';\nimport { getInputObjects } from './objects.js';\nimport type { Resolution } from '@mysten/ledgerjs-hw-app-sui';\n\nexport { getInputObjects } from './objects.js';\n\n/**\n * Configuration options for initializing the LedgerSigner.\n */\nexport interface LedgerSignerOptions {\n\tpublicKey: Ed25519PublicKey;\n\tderivationPath: string;\n\tledgerClient: SuiLedgerClient;\n\tsuiClient: ClientWithCoreApi;\n}\n\n/**\n * Ledger integrates with the Sui blockchain to provide signing capabilities using Ledger devices.\n */\nexport class LedgerSigner extends Signer {\n\t#derivationPath: string;\n\t#publicKey: Ed25519PublicKey;\n\t#ledgerClient: SuiLedgerClient;\n\t#suiClient: ClientWithCoreApi;\n\n\t/**\n\t * Creates an instance of LedgerSigner. It's expected to call the static `fromDerivationPath` method to create an instance.\n\t * @example\n\t * ```\n\t * const signer = await LedgerSigner.fromDerivationPath(derivationPath, options);\n\t * ```\n\t */\n\tconstructor({ publicKey, derivationPath, ledgerClient, suiClient }: LedgerSignerOptions) {\n\t\tsuper();\n\t\tthis.#publicKey = publicKey;\n\t\tthis.#derivationPath = derivationPath;\n\t\tthis.#ledgerClient = ledgerClient;\n\t\tthis.#suiClient = suiClient;\n\t}\n\n\t/**\n\t * Retrieves the key scheme used by this signer.\n\t */\n\toverride getKeyScheme() {\n\t\treturn 'ED25519' as const;\n\t}\n\n\t/**\n\t * Retrieves the public key associated with this signer.\n\t * @returns The Ed25519PublicKey instance.\n\t */\n\toverride getPublicKey() {\n\t\treturn this.#publicKey;\n\t}\n\n\t/**\n\t * Signs the provided transaction bytes.\n\t * @returns The signed transaction bytes and signature.\n\t */\n\toverride async signTransaction(\n\t\tbytes: Uint8Array,\n\t\tbcsObjects?: Uint8Array[],\n\t\tresolution?: Resolution,\n\t): Promise<SignatureWithBytes> {\n\t\tconst transactionOptions = bcsObjects\n\t\t\t? { bcsObjects }\n\t\t\t: await getInputObjects(Transaction.from(bytes), this.#suiClient).catch(() => ({\n\t\t\t\t\t// Fail gracefully so network errors or serialization issues don't break transaction signing:\n\t\t\t\t\tbcsObjects: [],\n\t\t\t\t}));\n\n\t\tconst intentMessage = messageWithIntent('TransactionData', bytes);\n\t\tconst { signature } = await this.#ledgerClient.signTransaction(\n\t\t\tthis.#derivationPath,\n\t\t\tintentMessage,\n\t\t\ttransactionOptions,\n\t\t\tresolution,\n\t\t);\n\n\t\treturn {\n\t\t\tbytes: toBase64(bytes),\n\t\t\tsignature: toSerializedSignature({\n\t\t\t\tsignature,\n\t\t\t\tsignatureScheme: this.getKeyScheme(),\n\t\t\t\tpublicKey: this.#publicKey,\n\t\t\t}),\n\t\t};\n\t}\n\n\t/**\n\t * Signs the provided personal message.\n\t * @returns The signed message bytes and signature.\n\t */\n\toverride async signPersonalMessage(bytes: Uint8Array): Promise<SignatureWithBytes> {\n\t\tconst intentMessage = messageWithIntent(\n\t\t\t'PersonalMessage',\n\t\t\tbcs.byteVector().serialize(bytes).toBytes(),\n\t\t);\n\t\tconst { signature } = await this.#ledgerClient.signTransaction(\n\t\t\tthis.#derivationPath,\n\t\t\tintentMessage,\n\t\t);\n\n\t\treturn {\n\t\t\tbytes: toBase64(bytes),\n\t\t\tsignature: toSerializedSignature({\n\t\t\t\tsignature,\n\t\t\t\tsignatureScheme: this.getKeyScheme(),\n\t\t\t\tpublicKey: this.#publicKey,\n\t\t\t}),\n\t\t};\n\t}\n\n\t/**\n\t * Prepares the signer by fetching and setting the public key from a Ledger device.\n\t * It is recommended to initialize an `LedgerSigner` instance using this function.\n\t * @returns A promise that resolves once a `LedgerSigner` instance is prepared (public key is set).\n\t */\n\tstatic async fromDerivationPath(\n\t\tderivationPath: string,\n\t\tledgerClient: SuiLedgerClient,\n\t\tsuiClient: ClientWithCoreApi,\n\t) {\n\t\tconst { publicKey } = await ledgerClient.getPublicKey(derivationPath);\n\t\tif (!publicKey) {\n\t\t\tthrow new Error('Failed to get public key from Ledger.');\n\t\t}\n\n\t\treturn new LedgerSigner({\n\t\t\tderivationPath,\n\t\t\tpublicKey: new Ed25519PublicKey(publicKey),\n\t\t\tledgerClient,\n\t\t\tsuiClient,\n\t\t});\n\t}\n\n\t/**\n\t * Generic signing is not supported by Ledger.\n\t * @throws Always throws an error indicating generic signing is unsupported.\n\t */\n\toverride sign(): never {\n\t\tthrow new Error('Ledger Signer does not support generic signing.');\n\t}\n\n\t/**\n\t * Generic signing is not supported by Ledger.\n\t * @throws Always throws an error indicating generic signing is unsupported.\n\t */\n\toverride signWithIntent(): never {\n\t\tthrow new Error('Ledger Signer does not support generic signing.');\n\t}\n}\n"],"mappings":";;;;;;;;;;;AA8BA,IAAa,eAAb,MAAa,qBAAqB,OAAO;CACxC;CACA;CACA;CACA;;;;;;;;CASA,YAAY,EAAE,WAAW,gBAAgB,cAAc,aAAkC;AACxF,SAAO;AACP,QAAKA,YAAa;AAClB,QAAKC,iBAAkB;AACvB,QAAKC,eAAgB;AACrB,QAAKC,YAAa;;;;;CAMnB,AAAS,eAAe;AACvB,SAAO;;;;;;CAOR,AAAS,eAAe;AACvB,SAAO,MAAKH;;;;;;CAOb,MAAe,gBACd,OACA,YACA,YAC8B;EAC9B,MAAM,qBAAqB,aACxB,EAAE,YAAY,GACd,MAAM,gBAAgB,YAAY,KAAK,MAAM,EAAE,MAAKG,UAAW,CAAC,aAAa,EAE7E,YAAY,EAAE,EACd,EAAE;EAEL,MAAM,gBAAgB,kBAAkB,mBAAmB,MAAM;EACjE,MAAM,EAAE,cAAc,MAAM,MAAKD,aAAc,gBAC9C,MAAKD,gBACL,eACA,oBACA,WACA;AAED,SAAO;GACN,OAAO,SAAS,MAAM;GACtB,WAAW,sBAAsB;IAChC;IACA,iBAAiB,KAAK,cAAc;IACpC,WAAW,MAAKD;IAChB,CAAC;GACF;;;;;;CAOF,MAAe,oBAAoB,OAAgD;EAClF,MAAM,gBAAgB,kBACrB,mBACA,IAAI,YAAY,CAAC,UAAU,MAAM,CAAC,SAAS,CAC3C;EACD,MAAM,EAAE,cAAc,MAAM,MAAKE,aAAc,gBAC9C,MAAKD,gBACL,cACA;AAED,SAAO;GACN,OAAO,SAAS,MAAM;GACtB,WAAW,sBAAsB;IAChC;IACA,iBAAiB,KAAK,cAAc;IACpC,WAAW,MAAKD;IAChB,CAAC;GACF;;;;;;;CAQF,aAAa,mBACZ,gBACA,cACA,WACC;EACD,MAAM,EAAE,cAAc,MAAM,aAAa,aAAa,eAAe;AACrE,MAAI,CAAC,UACJ,OAAM,IAAI,MAAM,wCAAwC;AAGzD,SAAO,IAAI,aAAa;GACvB;GACA,WAAW,IAAI,iBAAiB,UAAU;GAC1C;GACA;GACA,CAAC;;;;;;CAOH,AAAS,OAAc;AACtB,QAAM,IAAI,MAAM,kDAAkD;;;;;;CAOnE,AAAS,iBAAwB;AAChC,QAAM,IAAI,MAAM,kDAAkD"}
@@ -0,0 +1,10 @@
1
+ import { Transaction } from "@mysten/sui/transactions";
2
+ import { ClientWithCoreApi } from "@mysten/sui/client";
3
+
4
+ //#region src/ledger/objects.d.ts
5
+ declare const getInputObjects: (transaction: Transaction, client: ClientWithCoreApi) => Promise<{
6
+ bcsObjects: Uint8Array<ArrayBuffer>[];
7
+ }>;
8
+ //#endregion
9
+ export { getInputObjects };
10
+ //# sourceMappingURL=objects.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objects.d.mts","names":[],"sources":["../../src/ledger/objects.ts"],"sourcesContent":[],"mappings":";;;;cAMa,+BAAsC,qBAAqB,sBAAiB;;AAAzF,CAAA,CAAA"}
@@ -0,0 +1,16 @@
1
+ //#region src/ledger/objects.ts
2
+ const getInputObjects = async (transaction, client) => {
3
+ const data = transaction.getData();
4
+ const gasObjectIds = data.gasData.payment?.map((object) => object.objectId) ?? [];
5
+ const inputObjectIds = data.inputs.map((input) => {
6
+ return input.$kind === "Object" && input.Object.$kind === "ImmOrOwnedObject" ? input.Object.ImmOrOwnedObject.objectId : null;
7
+ }).filter((objectId) => !!objectId);
8
+ return { bcsObjects: (await client.core.getObjects({
9
+ objectIds: [...gasObjectIds, ...inputObjectIds],
10
+ include: { objectBcs: true }
11
+ })).objects.filter((obj) => !(obj instanceof Error)).map((object) => object.objectBcs).filter((bytes) => !!bytes) };
12
+ };
13
+
14
+ //#endregion
15
+ export { getInputObjects };
16
+ //# sourceMappingURL=objects.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objects.mjs","names":[],"sources":["../../src/ledger/objects.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Transaction } from '@mysten/sui/transactions';\nimport type { ClientWithCoreApi } from '@mysten/sui/client';\n\nexport const getInputObjects = async (transaction: Transaction, client: ClientWithCoreApi) => {\n\tconst data = transaction.getData();\n\n\tconst gasObjectIds = data.gasData.payment?.map((object) => object.objectId) ?? [];\n\tconst inputObjectIds = data.inputs\n\t\t.map((input) => {\n\t\t\treturn input.$kind === 'Object' && input.Object.$kind === 'ImmOrOwnedObject'\n\t\t\t\t? input.Object.ImmOrOwnedObject.objectId\n\t\t\t\t: null;\n\t\t})\n\t\t.filter((objectId): objectId is string => !!objectId);\n\n\tconst response = await client.core.getObjects({\n\t\tobjectIds: [...gasObjectIds, ...inputObjectIds],\n\t\tinclude: {\n\t\t\tobjectBcs: true,\n\t\t},\n\t});\n\n\tconst bcsObjects = response.objects\n\t\t.filter((obj): obj is Exclude<typeof obj, Error> => !(obj instanceof Error))\n\t\t.map((object) => object.objectBcs)\n\t\t.filter((bytes): bytes is Uint8Array<ArrayBuffer> => !!bytes);\n\n\treturn { bcsObjects };\n};\n"],"mappings":";AAMA,MAAa,kBAAkB,OAAO,aAA0B,WAA8B;CAC7F,MAAM,OAAO,YAAY,SAAS;CAElC,MAAM,eAAe,KAAK,QAAQ,SAAS,KAAK,WAAW,OAAO,SAAS,IAAI,EAAE;CACjF,MAAM,iBAAiB,KAAK,OAC1B,KAAK,UAAU;AACf,SAAO,MAAM,UAAU,YAAY,MAAM,OAAO,UAAU,qBACvD,MAAM,OAAO,iBAAiB,WAC9B;GACF,CACD,QAAQ,aAAiC,CAAC,CAAC,SAAS;AActD,QAAO,EAAE,aAZQ,MAAM,OAAO,KAAK,WAAW;EAC7C,WAAW,CAAC,GAAG,cAAc,GAAG,eAAe;EAC/C,SAAS,EACR,WAAW,MACX;EACD,CAAC,EAE0B,QAC1B,QAAQ,QAA2C,EAAE,eAAe,OAAO,CAC3E,KAAK,WAAW,OAAO,UAAU,CACjC,QAAQ,UAA4C,CAAC,CAAC,MAAM,EAEzC"}
@@ -0,0 +1,71 @@
1
+ import { p256 } from "@noble/curves/nist.js";
2
+ import { secp256k1 } from "@noble/curves/secp256k1.js";
3
+ import { ASN1Construction, ASN1TagClass, DERElement } from "asn1-ts";
4
+
5
+ //#region src/utils/utils.ts
6
+ /** The total number of bits in the DER bit string for the uncompressed public key. */
7
+ const DER_BIT_STRING_LENGTH = 520;
8
+ /** The total number of bytes corresponding to the DER bit string length. */
9
+ const DER_BYTES_LENGTH = DER_BIT_STRING_LENGTH / 8;
10
+ /**
11
+ * Converts an array of bits into a byte array.
12
+ *
13
+ * @param bitsArray - A `Uint8ClampedArray` representing the bits to convert.
14
+ * @returns A `Uint8Array` containing the corresponding bytes.
15
+ *
16
+ * @throws {Error} If the input array does not have the expected length.
17
+ */
18
+ function bitsToBytes(bitsArray) {
19
+ const bytes = new Uint8Array(DER_BYTES_LENGTH);
20
+ for (let i = 0; i < DER_BIT_STRING_LENGTH; i++) if (bitsArray[i] === 1) bytes[Math.floor(i / 8)] |= 1 << 7 - i % 8;
21
+ return bytes;
22
+ }
23
+ function publicKeyFromDER(derBytes) {
24
+ const encodedData = derBytes;
25
+ const derElement = new DERElement();
26
+ derElement.fromBytes(encodedData);
27
+ if (!(derElement.tagClass === ASN1TagClass.universal && derElement.construction === ASN1Construction.constructed)) throw new Error("Unexpected ASN.1 structure");
28
+ const publicKeyElement = derElement.components[1];
29
+ if (!publicKeyElement) throw new Error("Public Key not found in the DER structure");
30
+ return compressPublicKeyClamped(publicKeyElement.bitString);
31
+ }
32
+ function getConcatenatedSignature(signature, keyScheme) {
33
+ if (!signature || signature.length === 0) throw new Error("Invalid signature");
34
+ const derElement = new DERElement();
35
+ derElement.fromBytes(signature);
36
+ const [r, s] = derElement.toJSON();
37
+ switch (keyScheme) {
38
+ case "Secp256k1": {
39
+ const sig = new secp256k1.Signature(BigInt(r), BigInt(s));
40
+ return (sig.hasHighS() ? new secp256k1.Signature(sig.r, secp256k1.Point.Fn.neg(sig.s)) : sig).toBytes("compact");
41
+ }
42
+ case "Secp256r1": {
43
+ const sig = new p256.Signature(BigInt(r), BigInt(s));
44
+ return (sig.hasHighS() ? new p256.Signature(sig.r, p256.Point.Fn.neg(sig.s)) : sig).toBytes("compact");
45
+ }
46
+ default: throw new Error("Unsupported key scheme");
47
+ }
48
+ }
49
+ /**
50
+ * Compresses an uncompressed public key into its compressed form.
51
+ *
52
+ * The uncompressed key must follow the DER bit string format as specified in [RFC 5480](https://datatracker.ietf.org/doc/html/rfc5480#section-2.2)
53
+ * and [SEC 1: Elliptic Curve Cryptography](https://www.secg.org/sec1-v2.pdf).
54
+ *
55
+ * @param uncompressedKey - A `Uint8ClampedArray` representing the uncompressed public key bits.
56
+ * @returns A `Uint8Array` containing the compressed public key.
57
+ *
58
+ * @throws {Error} If the uncompressed key has an unexpected length or does not start with the expected prefix.
59
+ */
60
+ function compressPublicKeyClamped(uncompressedKey) {
61
+ if (uncompressedKey.length !== DER_BIT_STRING_LENGTH) throw new Error("Unexpected length for an uncompressed public key");
62
+ const uncompressedBytes = bitsToBytes(uncompressedKey);
63
+ if (uncompressedBytes[0] !== 4) throw new Error("Public key does not start with 0x04");
64
+ const xCoord = uncompressedBytes.slice(1, 33);
65
+ const parityByte = uncompressedBytes[64] % 2 === 0 ? 2 : 3;
66
+ return new Uint8Array([parityByte, ...xCoord]);
67
+ }
68
+
69
+ //#endregion
70
+ export { getConcatenatedSignature, publicKeyFromDER };
71
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","names":["secp256r1"],"sources":["../../src/utils/utils.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { p256 as secp256r1 } from '@noble/curves/nist.js';\nimport { secp256k1 } from '@noble/curves/secp256k1.js';\nimport { ASN1Construction, ASN1TagClass, DERElement } from 'asn1-ts';\n\n/** The total number of bits in the DER bit string for the uncompressed public key. */\nexport const DER_BIT_STRING_LENGTH = 520;\n\n/** The total number of bytes corresponding to the DER bit string length. */\nexport const DER_BYTES_LENGTH = DER_BIT_STRING_LENGTH / 8;\n\n// Reference Specifications:\n// https://datatracker.ietf.org/doc/html/rfc5480#section-2.2\n// https://www.secg.org/sec1-v2.pdf\n\n/**\n * Converts an array of bits into a byte array.\n *\n * @param bitsArray - A `Uint8ClampedArray` representing the bits to convert.\n * @returns A `Uint8Array` containing the corresponding bytes.\n *\n * @throws {Error} If the input array does not have the expected length.\n */\nfunction bitsToBytes(bitsArray: Uint8ClampedArray): Uint8Array {\n\tconst bytes = new Uint8Array(DER_BYTES_LENGTH);\n\tfor (let i = 0; i < DER_BIT_STRING_LENGTH; i++) {\n\t\tif (bitsArray[i] === 1) {\n\t\t\tbytes[Math.floor(i / 8)] |= 1 << (7 - (i % 8));\n\t\t}\n\t}\n\treturn bytes;\n}\n\nexport function publicKeyFromDER(derBytes: Uint8Array) {\n\tconst encodedData: Uint8Array = derBytes;\n\tconst derElement = new DERElement();\n\tderElement.fromBytes(encodedData);\n\n\t// Validate the ASN.1 structure of the public key\n\tif (\n\t\t!(\n\t\t\tderElement.tagClass === ASN1TagClass.universal &&\n\t\t\tderElement.construction === ASN1Construction.constructed\n\t\t)\n\t) {\n\t\tthrow new Error('Unexpected ASN.1 structure');\n\t}\n\n\tconst components = derElement.components;\n\tconst publicKeyElement = components[1];\n\n\tif (!publicKeyElement) {\n\t\tthrow new Error('Public Key not found in the DER structure');\n\t}\n\n\treturn compressPublicKeyClamped(publicKeyElement.bitString);\n}\n\nexport function getConcatenatedSignature(signature: Uint8Array, keyScheme: string) {\n\tif (!signature || signature.length === 0) {\n\t\tthrow new Error('Invalid signature');\n\t}\n\n\t// Initialize a DERElement to parse the DER-encoded signature\n\tconst derElement = new DERElement();\n\tderElement.fromBytes(signature);\n\n\tconst [r, s] = derElement.toJSON() as [string, string];\n\n\tswitch (keyScheme) {\n\t\tcase 'Secp256k1': {\n\t\t\tconst sig = new secp256k1.Signature(BigInt(r), BigInt(s));\n\t\t\tconst normalized = sig.hasHighS()\n\t\t\t\t? new secp256k1.Signature(sig.r, secp256k1.Point.Fn.neg(sig.s))\n\t\t\t\t: sig;\n\n\t\t\treturn normalized.toBytes('compact') as Uint8Array<ArrayBuffer>;\n\t\t}\n\t\tcase 'Secp256r1': {\n\t\t\tconst sig = new secp256r1.Signature(BigInt(r), BigInt(s));\n\t\t\tconst normalized = sig.hasHighS()\n\t\t\t\t? new secp256r1.Signature(sig.r, secp256r1.Point.Fn.neg(sig.s))\n\t\t\t\t: sig;\n\n\t\t\treturn normalized.toBytes('compact') as Uint8Array<ArrayBuffer>;\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error('Unsupported key scheme');\n\t}\n}\n\n/**\n * Compresses an uncompressed public key into its compressed form.\n *\n * The uncompressed key must follow the DER bit string format as specified in [RFC 5480](https://datatracker.ietf.org/doc/html/rfc5480#section-2.2)\n * and [SEC 1: Elliptic Curve Cryptography](https://www.secg.org/sec1-v2.pdf).\n *\n * @param uncompressedKey - A `Uint8ClampedArray` representing the uncompressed public key bits.\n * @returns A `Uint8Array` containing the compressed public key.\n *\n * @throws {Error} If the uncompressed key has an unexpected length or does not start with the expected prefix.\n */\nexport function compressPublicKeyClamped(uncompressedKey: Uint8ClampedArray): Uint8Array {\n\tif (uncompressedKey.length !== DER_BIT_STRING_LENGTH) {\n\t\tthrow new Error('Unexpected length for an uncompressed public key');\n\t}\n\n\t// Convert bits to bytes\n\tconst uncompressedBytes = bitsToBytes(uncompressedKey);\n\n\t// Ensure the public key starts with the standard uncompressed prefix 0x04\n\tif (uncompressedBytes[0] !== 0x04) {\n\t\tthrow new Error('Public key does not start with 0x04');\n\t}\n\n\t// Extract X-Coordinate (skip the first byte, which is the prefix 0x04)\n\tconst xCoord = uncompressedBytes.slice(1, 33);\n\n\t// Determine parity byte for Y coordinate based on the last byte\n\tconst yCoordLastByte = uncompressedBytes[64];\n\tconst parityByte = yCoordLastByte % 2 === 0 ? 0x02 : 0x03;\n\n\t// Return the compressed public key consisting of the parity byte and X-coordinate\n\treturn new Uint8Array([parityByte, ...xCoord]);\n}\n"],"mappings":";;;;;;AAQA,MAAa,wBAAwB;;AAGrC,MAAa,mBAAmB,wBAAwB;;;;;;;;;AAcxD,SAAS,YAAY,WAA0C;CAC9D,MAAM,QAAQ,IAAI,WAAW,iBAAiB;AAC9C,MAAK,IAAI,IAAI,GAAG,IAAI,uBAAuB,IAC1C,KAAI,UAAU,OAAO,EACpB,OAAM,KAAK,MAAM,IAAI,EAAE,KAAK,KAAM,IAAK,IAAI;AAG7C,QAAO;;AAGR,SAAgB,iBAAiB,UAAsB;CACtD,MAAM,cAA0B;CAChC,MAAM,aAAa,IAAI,YAAY;AACnC,YAAW,UAAU,YAAY;AAGjC,KACC,EACC,WAAW,aAAa,aAAa,aACrC,WAAW,iBAAiB,iBAAiB,aAG9C,OAAM,IAAI,MAAM,6BAA6B;CAI9C,MAAM,mBADa,WAAW,WACM;AAEpC,KAAI,CAAC,iBACJ,OAAM,IAAI,MAAM,4CAA4C;AAG7D,QAAO,yBAAyB,iBAAiB,UAAU;;AAG5D,SAAgB,yBAAyB,WAAuB,WAAmB;AAClF,KAAI,CAAC,aAAa,UAAU,WAAW,EACtC,OAAM,IAAI,MAAM,oBAAoB;CAIrC,MAAM,aAAa,IAAI,YAAY;AACnC,YAAW,UAAU,UAAU;CAE/B,MAAM,CAAC,GAAG,KAAK,WAAW,QAAQ;AAElC,SAAQ,WAAR;EACC,KAAK,aAAa;GACjB,MAAM,MAAM,IAAI,UAAU,UAAU,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC;AAKzD,WAJmB,IAAI,UAAU,GAC9B,IAAI,UAAU,UAAU,IAAI,GAAG,UAAU,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC,GAC7D,KAEe,QAAQ,UAAU;;EAErC,KAAK,aAAa;GACjB,MAAM,MAAM,IAAIA,KAAU,UAAU,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC;AAKzD,WAJmB,IAAI,UAAU,GAC9B,IAAIA,KAAU,UAAU,IAAI,GAAGA,KAAU,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC,GAC7D,KAEe,QAAQ,UAAU;;EAErC,QACC,OAAM,IAAI,MAAM,yBAAyB;;;;;;;;;;;;;;AAe5C,SAAgB,yBAAyB,iBAAgD;AACxF,KAAI,gBAAgB,WAAW,sBAC9B,OAAM,IAAI,MAAM,mDAAmD;CAIpE,MAAM,oBAAoB,YAAY,gBAAgB;AAGtD,KAAI,kBAAkB,OAAO,EAC5B,OAAM,IAAI,MAAM,sCAAsC;CAIvD,MAAM,SAAS,kBAAkB,MAAM,GAAG,GAAG;CAI7C,MAAM,aADiB,kBAAkB,MACL,MAAM,IAAI,IAAO;AAGrD,QAAO,IAAI,WAAW,CAAC,YAAY,GAAG,OAAO,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { SignatureScheme, Signer } from "@mysten/sui/cryptography";
2
+ import { Secp256r1PublicKey } from "@mysten/sui/keypairs/secp256r1";
3
+
4
+ //#region src/webcrypto/index.d.ts
5
+ interface ExportedWebCryptoKeypair {
6
+ privateKey: CryptoKey;
7
+ publicKey: Uint8Array<ArrayBuffer>;
8
+ }
9
+ declare class WebCryptoSigner extends Signer {
10
+ #private;
11
+ privateKey: CryptoKey;
12
+ static generate({
13
+ extractable
14
+ }?: {
15
+ extractable?: boolean;
16
+ }): Promise<WebCryptoSigner>;
17
+ /**
18
+ * Imports a keypair using the value returned by `export()`.
19
+ */
20
+ static import(data: ExportedWebCryptoKeypair): WebCryptoSigner;
21
+ getKeyScheme(): SignatureScheme;
22
+ constructor(privateKey: CryptoKey, publicKey: Uint8Array);
23
+ /**
24
+ * Exports the keypair so that it can be stored in IndexedDB.
25
+ */
26
+ export(): ExportedWebCryptoKeypair;
27
+ getPublicKey(): Secp256r1PublicKey;
28
+ sign(bytes: Uint8Array): Promise<Uint8Array<ArrayBuffer>>;
29
+ }
30
+ //#endregion
31
+ export { ExportedWebCryptoKeypair, WebCryptoSigner };
32
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/webcrypto/index.ts"],"sourcesContent":[],"mappings":";;;;UAuBiB,wBAAA;EAAA,UAAA,EACJ,SADI;EACJ,SAAA,EACD,UADC,CACU,WADV,CAAA;;AACD,cAGC,eAAA,SAAwB,MAAA,CAHzB;EAAU,CAAA,OAAA;EAGT,UAAA,EACA,SADgB;EAChB,OAAA,QAAA,CAAA;IAAA;EAIiE,CAAA,CAJjE,EAAA;IAIY,WAAA,CAAA,EAAA,OAAA;EAAqD,CAAA,CAAA,EAAA,OAAA,CAAA,eAAA,CAAA;EAAA;;;EAyB7D,OAAA,MAAA,CAAA,IAAA,EAJI,wBAIJ,CAAA,EAJ4B,eAI5B;EAIQ,YAAA,CAAA,CAAA,EAJR,eAIQ;EAAsB,WAAA,CAAA,UAAA,EAAtB,SAAsB,EAAA,SAAA,EAAA,UAAA;EASpC;;;EAsBwC,MAAA,CAAA,CAAA,EAtBxC,wBAsBwC;EAAX,YAAA,CAAA,CAAA,EAJ3B,kBAI2B;EAAR,IAAA,CAAA,KAAA,EAAb,UAAa,CAAA,EAAA,OAAA,CAAQ,UAAR,CAAmB,WAAnB,CAAA,CAAA"}
@@ -0,0 +1,70 @@
1
+ import { Signer } from "@mysten/sui/cryptography";
2
+ import { p256 } from "@noble/curves/nist.js";
3
+ import { Secp256r1PublicKey } from "@mysten/sui/keypairs/secp256r1";
4
+
5
+ //#region src/webcrypto/index.ts
6
+ function getCompressedPublicKey(publicKey) {
7
+ const rawBytes = new Uint8Array(publicKey);
8
+ const x = rawBytes.slice(1, 33);
9
+ const prefix = (rawBytes.slice(33, 65)[31] & 1) === 0 ? 2 : 3;
10
+ const compressed = new Uint8Array(Secp256r1PublicKey.SIZE);
11
+ compressed[0] = prefix;
12
+ compressed.set(x, 1);
13
+ return compressed;
14
+ }
15
+ var WebCryptoSigner = class WebCryptoSigner extends Signer {
16
+ #publicKey;
17
+ static async generate({ extractable = false } = {}) {
18
+ const keypair = await globalThis.crypto.subtle.generateKey({
19
+ name: "ECDSA",
20
+ namedCurve: "P-256"
21
+ }, extractable, ["sign", "verify"]);
22
+ const publicKey = await globalThis.crypto.subtle.exportKey("raw", keypair.publicKey);
23
+ return new WebCryptoSigner(keypair.privateKey, getCompressedPublicKey(new Uint8Array(publicKey)));
24
+ }
25
+ /**
26
+ * Imports a keypair using the value returned by `export()`.
27
+ */
28
+ static import(data) {
29
+ return new WebCryptoSigner(data.privateKey, data.publicKey);
30
+ }
31
+ getKeyScheme() {
32
+ return "Secp256r1";
33
+ }
34
+ constructor(privateKey, publicKey) {
35
+ super();
36
+ this.privateKey = privateKey;
37
+ this.#publicKey = new Secp256r1PublicKey(publicKey);
38
+ }
39
+ /**
40
+ * Exports the keypair so that it can be stored in IndexedDB.
41
+ */
42
+ export() {
43
+ const exportedKeypair = {
44
+ privateKey: this.privateKey,
45
+ publicKey: this.#publicKey.toRawBytes()
46
+ };
47
+ Object.defineProperty(exportedKeypair, "toJSON", {
48
+ enumerable: false,
49
+ value: () => {
50
+ throw new Error("The exported keypair must not be serialized. It must be stored in IndexedDB directly.");
51
+ }
52
+ });
53
+ return exportedKeypair;
54
+ }
55
+ getPublicKey() {
56
+ return this.#publicKey;
57
+ }
58
+ async sign(bytes) {
59
+ const rawSignature = await globalThis.crypto.subtle.sign({
60
+ name: "ECDSA",
61
+ hash: "SHA-256"
62
+ }, this.privateKey, bytes);
63
+ const signature = p256.Signature.fromBytes(new Uint8Array(rawSignature));
64
+ return (signature.hasHighS() ? new p256.Signature(signature.r, p256.Point.Fn.neg(signature.s)) : signature).toBytes("compact");
65
+ }
66
+ };
67
+
68
+ //#endregion
69
+ export { WebCryptoSigner };
70
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["#publicKey","secp256r1"],"sources":["../../src/webcrypto/index.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SignatureScheme } from '@mysten/sui/cryptography';\nimport { Signer } from '@mysten/sui/cryptography';\nimport { Secp256r1PublicKey } from '@mysten/sui/keypairs/secp256r1';\nimport { p256 as secp256r1 } from '@noble/curves/nist.js';\n\n// Convert from uncompressed (65 bytes) to compressed (33 bytes) format\nfunction getCompressedPublicKey(publicKey: Uint8Array) {\n\tconst rawBytes = new Uint8Array(publicKey);\n\tconst x = rawBytes.slice(1, 33);\n\tconst y = rawBytes.slice(33, 65);\n\n\tconst prefix = (y[31] & 1) === 0 ? 0x02 : 0x03;\n\n\tconst compressed = new Uint8Array(Secp256r1PublicKey.SIZE);\n\tcompressed[0] = prefix;\n\tcompressed.set(x, 1);\n\n\treturn compressed;\n}\n\nexport interface ExportedWebCryptoKeypair {\n\tprivateKey: CryptoKey;\n\tpublicKey: Uint8Array<ArrayBuffer>;\n}\n\nexport class WebCryptoSigner extends Signer {\n\tprivateKey: CryptoKey;\n\n\t#publicKey: Secp256r1PublicKey;\n\n\tstatic async generate({ extractable = false }: { extractable?: boolean } = {}) {\n\t\tconst keypair = await globalThis.crypto.subtle.generateKey(\n\t\t\t{\n\t\t\t\tname: 'ECDSA',\n\t\t\t\tnamedCurve: 'P-256',\n\t\t\t},\n\t\t\textractable,\n\t\t\t['sign', 'verify'],\n\t\t);\n\n\t\tconst publicKey = await globalThis.crypto.subtle.exportKey('raw', keypair.publicKey);\n\n\t\treturn new WebCryptoSigner(\n\t\t\tkeypair.privateKey,\n\t\t\tgetCompressedPublicKey(new Uint8Array(publicKey)),\n\t\t);\n\t}\n\n\t/**\n\t * Imports a keypair using the value returned by `export()`.\n\t */\n\tstatic import(data: ExportedWebCryptoKeypair) {\n\t\treturn new WebCryptoSigner(data.privateKey, data.publicKey);\n\t}\n\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'Secp256r1';\n\t}\n\n\tconstructor(privateKey: CryptoKey, publicKey: Uint8Array) {\n\t\tsuper();\n\t\tthis.privateKey = privateKey;\n\t\tthis.#publicKey = new Secp256r1PublicKey(publicKey);\n\t}\n\n\t/**\n\t * Exports the keypair so that it can be stored in IndexedDB.\n\t */\n\texport(): ExportedWebCryptoKeypair {\n\t\tconst exportedKeypair = {\n\t\t\tprivateKey: this.privateKey,\n\t\t\tpublicKey: this.#publicKey.toRawBytes(),\n\t\t};\n\n\t\tObject.defineProperty(exportedKeypair, 'toJSON', {\n\t\t\tenumerable: false,\n\t\t\tvalue: () => {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'The exported keypair must not be serialized. It must be stored in IndexedDB directly.',\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\n\t\treturn exportedKeypair;\n\t}\n\n\tgetPublicKey() {\n\t\treturn this.#publicKey;\n\t}\n\n\tasync sign(bytes: Uint8Array): Promise<Uint8Array<ArrayBuffer>> {\n\t\tconst rawSignature = await globalThis.crypto.subtle.sign(\n\t\t\t{\n\t\t\t\tname: 'ECDSA',\n\t\t\t\thash: 'SHA-256',\n\t\t\t},\n\t\t\tthis.privateKey,\n\t\t\tbytes as BufferSource,\n\t\t);\n\n\t\tconst signature = secp256r1.Signature.fromBytes(new Uint8Array(rawSignature));\n\t\tconst normalizedSig = signature.hasHighS()\n\t\t\t? new secp256r1.Signature(signature.r, secp256r1.Point.Fn.neg(signature.s))\n\t\t\t: signature;\n\n\t\treturn normalizedSig.toBytes('compact') as Uint8Array<ArrayBuffer>;\n\t}\n}\n"],"mappings":";;;;;AASA,SAAS,uBAAuB,WAAuB;CACtD,MAAM,WAAW,IAAI,WAAW,UAAU;CAC1C,MAAM,IAAI,SAAS,MAAM,GAAG,GAAG;CAG/B,MAAM,UAFI,SAAS,MAAM,IAAI,GAAG,CAEd,MAAM,OAAO,IAAI,IAAO;CAE1C,MAAM,aAAa,IAAI,WAAW,mBAAmB,KAAK;AAC1D,YAAW,KAAK;AAChB,YAAW,IAAI,GAAG,EAAE;AAEpB,QAAO;;AAQR,IAAa,kBAAb,MAAa,wBAAwB,OAAO;CAG3C;CAEA,aAAa,SAAS,EAAE,cAAc,UAAqC,EAAE,EAAE;EAC9E,MAAM,UAAU,MAAM,WAAW,OAAO,OAAO,YAC9C;GACC,MAAM;GACN,YAAY;GACZ,EACD,aACA,CAAC,QAAQ,SAAS,CAClB;EAED,MAAM,YAAY,MAAM,WAAW,OAAO,OAAO,UAAU,OAAO,QAAQ,UAAU;AAEpF,SAAO,IAAI,gBACV,QAAQ,YACR,uBAAuB,IAAI,WAAW,UAAU,CAAC,CACjD;;;;;CAMF,OAAO,OAAO,MAAgC;AAC7C,SAAO,IAAI,gBAAgB,KAAK,YAAY,KAAK,UAAU;;CAG5D,eAAgC;AAC/B,SAAO;;CAGR,YAAY,YAAuB,WAAuB;AACzD,SAAO;AACP,OAAK,aAAa;AAClB,QAAKA,YAAa,IAAI,mBAAmB,UAAU;;;;;CAMpD,SAAmC;EAClC,MAAM,kBAAkB;GACvB,YAAY,KAAK;GACjB,WAAW,MAAKA,UAAW,YAAY;GACvC;AAED,SAAO,eAAe,iBAAiB,UAAU;GAChD,YAAY;GACZ,aAAa;AACZ,UAAM,IAAI,MACT,wFACA;;GAEF,CAAC;AAEF,SAAO;;CAGR,eAAe;AACd,SAAO,MAAKA;;CAGb,MAAM,KAAK,OAAqD;EAC/D,MAAM,eAAe,MAAM,WAAW,OAAO,OAAO,KACnD;GACC,MAAM;GACN,MAAM;GACN,EACD,KAAK,YACL,MACA;EAED,MAAM,YAAYC,KAAU,UAAU,UAAU,IAAI,WAAW,aAAa,CAAC;AAK7E,UAJsB,UAAU,UAAU,GACvC,IAAIA,KAAU,UAAU,UAAU,GAAGA,KAAU,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC,GACzE,WAEkB,QAAQ,UAAU"}
package/package.json CHANGED
@@ -1,26 +1,30 @@
1
1
  {
2
2
  "name": "@mysten/signers",
3
- "version": "0.6.2",
3
+ "version": "1.0.1",
4
4
  "description": "A collection of signers for various providers",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Mysten Labs <build@mystenlabs.com>",
7
- "type": "commonjs",
7
+ "type": "module",
8
8
  "exports": {
9
9
  "./aws": {
10
- "import": "./dist/esm/aws/index.js",
11
- "require": "./dist/cjs/aws/index.js"
10
+ "types": "./dist/aws/index.d.mts",
11
+ "import": "./dist/aws/index.mjs",
12
+ "default": "./dist/aws/index.mjs"
12
13
  },
13
14
  "./gcp": {
14
- "import": "./dist/esm/gcp/index.js",
15
- "require": "./dist/cjs/gcp/index.js"
15
+ "types": "./dist/gcp/index.d.mts",
16
+ "import": "./dist/gcp/index.mjs",
17
+ "default": "./dist/gcp/index.mjs"
16
18
  },
17
19
  "./ledger": {
18
- "import": "./dist/esm/ledger/index.js",
19
- "require": "./dist/cjs/ledger/index.js"
20
+ "types": "./dist/ledger/index.d.mts",
21
+ "import": "./dist/ledger/index.mjs",
22
+ "default": "./dist/ledger/index.mjs"
20
23
  },
21
24
  "./webcrypto": {
22
- "import": "./dist/esm/webcrypto/index.js",
23
- "require": "./dist/cjs/webcrypto/index.js"
25
+ "types": "./dist/webcrypto/index.d.mts",
26
+ "import": "./dist/webcrypto/index.mjs",
27
+ "default": "./dist/webcrypto/index.mjs"
24
28
  }
25
29
  },
26
30
  "sideEffects": false,
@@ -38,39 +42,41 @@
38
42
  ],
39
43
  "repository": {
40
44
  "type": "git",
41
- "url": "git+https://github.com/mystenlabs/ts-sdks.git"
45
+ "url": "git+https://github.com/MystenLabs/ts-sdks.git"
42
46
  },
43
47
  "bugs": {
44
48
  "url": "https://github.com/mystenlabs/ts-sdks/issues"
45
49
  },
46
50
  "homepage": "https://github.com/MystenLabs/ts-sdks/tree/main/packages/signers#readme",
47
51
  "devDependencies": {
48
- "@types/node": "^22.15.29",
49
- "dotenv": "^17.2.2",
50
- "typescript": "^5.9.2",
51
- "vitest": "^3.2.4",
52
- "@mysten/build-scripts": "0.0.0"
52
+ "@types/node": "^25.0.8",
53
+ "dotenv": "^17.2.3",
54
+ "typescript": "^5.9.3",
55
+ "vitest": "^4.0.17",
56
+ "@mysten/sui": "^2.3.2"
53
57
  },
54
58
  "dependencies": {
55
- "@google-cloud/kms": "^4.5.0",
56
- "@noble/curves": "=1.9.4",
57
- "@noble/hashes": "^1.8.0",
58
- "asn1-ts": "^8.0.2",
59
- "@mysten/ledgerjs-hw-app-sui": "0.7.0",
60
- "@mysten/sui": "1.45.2"
59
+ "@google-cloud/kms": "^5.2.1",
60
+ "@noble/curves": "^2.0.1",
61
+ "@noble/hashes": "^2.0.1",
62
+ "asn1-ts": "^11.0.5",
63
+ "@mysten/ledgerjs-hw-app-sui": "^0.7.1"
61
64
  },
62
65
  "engines": {
63
- "node": ">=20"
66
+ "node": ">=22"
67
+ },
68
+ "peerDependencies": {
69
+ "@mysten/sui": "^2.3.2"
64
70
  },
65
71
  "scripts": {
66
72
  "clean": "rm -rf tsconfig.tsbuildinfo ./dist",
67
- "build": "build-package",
73
+ "build": "rm -rf dist && tsc --noEmit && tsdown",
68
74
  "prettier:check": "prettier -c --ignore-unknown .",
69
75
  "prettier:fix": "prettier -w --ignore-unknown .",
70
- "eslint:check": "eslint --max-warnings=0 .",
71
- "eslint:fix": "pnpm run eslint:check --fix",
72
- "lint": "pnpm run eslint:check && pnpm run prettier:check",
73
- "lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix",
76
+ "oxlint:check": "oxlint .",
77
+ "oxlint:fix": "oxlint --fix",
78
+ "lint": "pnpm run oxlint:check && pnpm run prettier:check",
79
+ "lint:fix": "pnpm run oxlint:fix && pnpm run prettier:fix",
74
80
  "test": "vitest run"
75
81
  }
76
82
  }
@@ -83,15 +83,6 @@ export class AwsKmsSigner extends Signer {
83
83
  return getConcatenatedSignature(fromBase64(signResponse.Signature), this.getKeyScheme());
84
84
  }
85
85
 
86
- /**
87
- * Synchronous signing is not supported by AWS KMS.
88
- * @throws Always throws an error indicating synchronous signing is unsupported.
89
- * @deprecated use `sign` instead
90
- */
91
- signData(): never {
92
- throw new Error('KMS Signer does not support sync signing');
93
- }
94
-
95
86
  /**
96
87
  * Prepares the signer by fetching and setting the public key from AWS KMS.
97
88
  * It is recommended to initialize an `AwsKmsSigner` instance using this function.
@@ -86,15 +86,6 @@ export class GcpKmsSigner extends Signer {
86
86
  return getConcatenatedSignature(signResponse.signature as Uint8Array, this.getKeyScheme());
87
87
  }
88
88
 
89
- /**
90
- * Synchronous signing is not supported by GCP KMS.
91
- * @throws Always throws an error indicating synchronous signing is unsupported.
92
- * @deprecated use `sign` instead
93
- */
94
- signData(): never {
95
- throw new Error('GCP Signer does not support sync signing');
96
- }
97
-
98
89
  /**
99
90
  * Creates a GCP KMS signer from the provided options.
100
91
  * Expects the credentials file to be set as an env variable
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import type SuiLedgerClient from '@mysten/ledgerjs-hw-app-sui';
5
- import type { SuiClient } from '@mysten/sui/client';
5
+ import type { ClientWithCoreApi } from '@mysten/sui/client';
6
6
  import type { SignatureWithBytes } from '@mysten/sui/cryptography';
7
7
  import { messageWithIntent, Signer, toSerializedSignature } from '@mysten/sui/cryptography';
8
8
  import { Ed25519PublicKey } from '@mysten/sui/keypairs/ed25519';
@@ -13,7 +13,6 @@ import { bcs } from '@mysten/sui/bcs';
13
13
  import { getInputObjects } from './objects.js';
14
14
  import type { Resolution } from '@mysten/ledgerjs-hw-app-sui';
15
15
 
16
- export { SuiMoveObject } from './bcs.js';
17
16
  export { getInputObjects } from './objects.js';
18
17
 
19
18
  /**
@@ -23,7 +22,7 @@ export interface LedgerSignerOptions {
23
22
  publicKey: Ed25519PublicKey;
24
23
  derivationPath: string;
25
24
  ledgerClient: SuiLedgerClient;
26
- suiClient: SuiClient;
25
+ suiClient: ClientWithCoreApi;
27
26
  }
28
27
 
29
28
  /**
@@ -33,7 +32,7 @@ export class LedgerSigner extends Signer {
33
32
  #derivationPath: string;
34
33
  #publicKey: Ed25519PublicKey;
35
34
  #ledgerClient: SuiLedgerClient;
36
- #suiClient: SuiClient;
35
+ #suiClient: ClientWithCoreApi;
37
36
 
38
37
  /**
39
38
  * Creates an instance of LedgerSigner. It's expected to call the static `fromDerivationPath` method to create an instance.
@@ -131,7 +130,7 @@ export class LedgerSigner extends Signer {
131
130
  static async fromDerivationPath(
132
131
  derivationPath: string,
133
132
  ledgerClient: SuiLedgerClient,
134
- suiClient: SuiClient,
133
+ suiClient: ClientWithCoreApi,
135
134
  ) {
136
135
  const { publicKey } = await ledgerClient.getPublicKey(derivationPath);
137
136
  if (!publicKey) {
@@ -2,10 +2,9 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import type { Transaction } from '@mysten/sui/transactions';
5
- import type { SuiClient } from '@mysten/sui/client';
6
- import { SuiMoveObject } from './bcs.js';
5
+ import type { ClientWithCoreApi } from '@mysten/sui/client';
7
6
 
8
- export const getInputObjects = async (transaction: Transaction, client: SuiClient) => {
7
+ export const getInputObjects = async (transaction: Transaction, client: ClientWithCoreApi) => {
9
8
  const data = transaction.getData();
10
9
 
11
10
  const gasObjectIds = data.gasData.payment?.map((object) => object.objectId) ?? [];
@@ -17,40 +16,17 @@ export const getInputObjects = async (transaction: Transaction, client: SuiClien
17
16
  })
18
17
  .filter((objectId): objectId is string => !!objectId);
19
18
 
20
- const objects = await client.multiGetObjects({
21
- ids: [...gasObjectIds, ...inputObjectIds],
22
- options: {
23
- showBcs: true,
24
- showPreviousTransaction: true,
25
- showStorageRebate: true,
26
- showOwner: true,
19
+ const response = await client.core.getObjects({
20
+ objectIds: [...gasObjectIds, ...inputObjectIds],
21
+ include: {
22
+ objectBcs: true,
27
23
  },
28
24
  });
29
25
 
30
- // NOTE: We should probably get rid of this manual serialization logic in favor of using the
31
- // already serialized object bytes from the GraphQL API once there is more mainstream support
32
- // for it + we can enforce the transport type on the Sui client.
33
- const bcsObjects = objects
34
- .map((object) => {
35
- if (object.error || !object.data || object.data.bcs?.dataType !== 'moveObject') {
36
- return null;
37
- }
38
-
39
- return SuiMoveObject.serialize({
40
- data: {
41
- MoveObject: {
42
- type: object.data.bcs.type,
43
- hasPublicTransfer: object.data.bcs.hasPublicTransfer,
44
- version: object.data.bcs.version,
45
- contents: object.data.bcs.bcsBytes,
46
- },
47
- },
48
- owner: object.data.owner!,
49
- previousTransaction: object.data.previousTransaction!,
50
- storageRebate: object.data.storageRebate!,
51
- }).toBytes();
52
- })
53
- .filter((bcsBytes): bcsBytes is Uint8Array<ArrayBuffer> => !!bcsBytes);
26
+ const bcsObjects = response.objects
27
+ .filter((obj): obj is Exclude<typeof obj, Error> => !(obj instanceof Error))
28
+ .map((object) => object.objectBcs)
29
+ .filter((bytes): bytes is Uint8Array<ArrayBuffer> => !!bytes);
54
30
 
55
31
  return { bcsObjects };
56
32
  };