@mysten/signers 1.0.2 → 1.0.5

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 (47) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +1 -1
  3. package/dist/aws/index.d.mts +1 -3
  4. package/dist/aws/index.mjs +2 -2
  5. package/dist/gcp/index.d.mts +1 -2
  6. package/dist/gcp/index.mjs +2 -2
  7. package/dist/ledger/index.d.mts +1 -74
  8. package/dist/ledger/index.mjs +2 -109
  9. package/dist/webcrypto/index.d.mts +1 -32
  10. package/dist/webcrypto/index.mjs +2 -69
  11. package/package.json +9 -19
  12. package/src/aws/index.ts +1 -6
  13. package/src/gcp/index.ts +1 -6
  14. package/src/ledger/index.ts +1 -160
  15. package/src/webcrypto/index.ts +1 -108
  16. package/dist/aws/aws-client.d.mts +0 -48
  17. package/dist/aws/aws-client.d.mts.map +0 -1
  18. package/dist/aws/aws-client.mjs +0 -46
  19. package/dist/aws/aws-client.mjs.map +0 -1
  20. package/dist/aws/aws-kms-signer.d.mts +0 -63
  21. package/dist/aws/aws-kms-signer.d.mts.map +0 -1
  22. package/dist/aws/aws-kms-signer.mjs +0 -78
  23. package/dist/aws/aws-kms-signer.mjs.map +0 -1
  24. package/dist/aws/aws4fetch.d.mts +0 -62
  25. package/dist/aws/aws4fetch.d.mts.map +0 -1
  26. package/dist/aws/aws4fetch.mjs +0 -313
  27. package/dist/aws/aws4fetch.mjs.map +0 -1
  28. package/dist/gcp/gcp-kms-client.d.mts +0 -71
  29. package/dist/gcp/gcp-kms-client.d.mts.map +0 -1
  30. package/dist/gcp/gcp-kms-client.mjs +0 -104
  31. package/dist/gcp/gcp-kms-client.mjs.map +0 -1
  32. package/dist/ledger/index.d.mts.map +0 -1
  33. package/dist/ledger/index.mjs.map +0 -1
  34. package/dist/ledger/objects.d.mts +0 -10
  35. package/dist/ledger/objects.d.mts.map +0 -1
  36. package/dist/ledger/objects.mjs +0 -16
  37. package/dist/ledger/objects.mjs.map +0 -1
  38. package/dist/utils/utils.mjs +0 -71
  39. package/dist/utils/utils.mjs.map +0 -1
  40. package/dist/webcrypto/index.d.mts.map +0 -1
  41. package/dist/webcrypto/index.mjs.map +0 -1
  42. package/src/aws/aws-client.ts +0 -107
  43. package/src/aws/aws-kms-signer.ts +0 -102
  44. package/src/aws/aws4fetch.ts +0 -502
  45. package/src/gcp/gcp-kms-client.ts +0 -156
  46. package/src/ledger/objects.ts +0 -32
  47. package/src/utils/utils.ts +0 -127
package/CHANGELOG.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # @mysten/signers
2
2
 
3
+ ## 1.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - f7de3e5: Restore docs in published tarballs.
8
+ - Updated dependencies [f7de3e5]
9
+ - @mysten/aws-kms-signer@0.1.2
10
+ - @mysten/gcp-kms-signer@0.1.2
11
+ - @mysten/ledger-signer@0.1.2
12
+ - @mysten/sui@2.16.2
13
+ - @mysten/webcrypto-signer@0.1.2
14
+
15
+ ## 1.0.4
16
+
17
+ ### Patch Changes
18
+
19
+ - 9e067cf: Validate the new per-package release flow end-to-end across every public @mysten package.
20
+ No functional changes — empty patch bump to force the orchestrator to dispatch every
21
+ release-<pkg>.yml workflow with `dry_run=false` so each package publishes via OIDC trusted
22
+ publishing.
23
+ - Updated dependencies [9e067cf]
24
+ - @mysten/aws-kms-signer@0.1.1
25
+ - @mysten/gcp-kms-signer@0.1.1
26
+ - @mysten/ledger-signer@0.1.1
27
+ - @mysten/sui@2.16.1
28
+ - @mysten/webcrypto-signer@0.1.1
29
+
30
+ ## 1.0.3
31
+
32
+ ### Patch Changes
33
+
34
+ - 75a32c1: Internal refactor: each backend now lives in its own package (`@mysten/aws-kms-signer`,
35
+ `@mysten/gcp-kms-signer`, `@mysten/ledger-signer`, `@mysten/webcrypto-signer`). The
36
+ `@mysten/signers/{aws,gcp,ledger,webcrypto}` subpaths now re-export from the new packages — no
37
+ public API change. To shrink your dependency tree, switch to importing from the per-backend
38
+ package directly.
39
+ - Updated dependencies [75a32c1]
40
+ - Updated dependencies [75a32c1]
41
+ - Updated dependencies [75a32c1]
42
+ - Updated dependencies [75a32c1]
43
+ - @mysten/aws-kms-signer@0.1.0
44
+ - @mysten/gcp-kms-signer@0.1.0
45
+ - @mysten/ledger-signer@0.1.0
46
+ - @mysten/webcrypto-signer@0.1.0
47
+
3
48
  ## 1.0.2
4
49
 
5
50
  ### Patch Changes
package/README.md CHANGED
@@ -195,7 +195,7 @@ console.log(signer.toSuiAddress());
195
195
 
196
196
  // Define a test transaction:
197
197
  const testTransaction = new Transaction();
198
- const transactionBytes = await testTransaction.build();
198
+ const transactionBytes = await testTransaction.build({ client: suiClient });
199
199
 
200
200
  // Sign a test transaction:
201
201
  const { signature } = await signer.signTransaction(transactionBytes);
@@ -1,3 +1 @@
1
- import { AwsClientOptions } from "./aws-client.mjs";
2
- import { AwsKmsSigner, AwsKmsSignerOptions } from "./aws-kms-signer.mjs";
3
- export { type AwsClientOptions, AwsKmsSigner, type AwsKmsSignerOptions };
1
+ export * from "@mysten/aws-kms-signer";
@@ -1,3 +1,3 @@
1
- import { AwsKmsSigner } from "./aws-kms-signer.mjs";
1
+ export * from "@mysten/aws-kms-signer"
2
2
 
3
- export { AwsKmsSigner };
3
+ export { };
@@ -1,2 +1 @@
1
- import { GcpKmsSigner, GcpKmsSignerOptions } from "./gcp-kms-client.mjs";
2
- export { GcpKmsSigner, type GcpKmsSignerOptions };
1
+ export * from "@mysten/gcp-kms-signer";
@@ -1,3 +1,3 @@
1
- import { GcpKmsSigner } from "./gcp-kms-client.mjs";
1
+ export * from "@mysten/gcp-kms-signer"
2
2
 
3
- export { GcpKmsSigner };
3
+ export { };
@@ -1,74 +1 @@
1
- import { getInputObjects } from "./objects.mjs";
2
- import { SignatureWithBytes, Signer } from "@mysten/sui/cryptography";
3
- import { Ed25519PublicKey } from "@mysten/sui/keypairs/ed25519";
4
- import SuiLedgerClient, { Resolution } from "@mysten/ledgerjs-hw-app-sui";
5
- import { ClientWithCoreApi } from "@mysten/sui/client";
6
-
7
- //#region src/ledger/index.d.ts
8
-
9
- /**
10
- * Configuration options for initializing the LedgerSigner.
11
- */
12
- interface LedgerSignerOptions {
13
- publicKey: Ed25519PublicKey;
14
- derivationPath: string;
15
- ledgerClient: SuiLedgerClient;
16
- suiClient: ClientWithCoreApi;
17
- }
18
- /**
19
- * Ledger integrates with the Sui blockchain to provide signing capabilities using Ledger devices.
20
- */
21
- declare class LedgerSigner extends Signer {
22
- #private;
23
- /**
24
- * Creates an instance of LedgerSigner. It's expected to call the static `fromDerivationPath` method to create an instance.
25
- * @example
26
- * ```
27
- * const signer = await LedgerSigner.fromDerivationPath(derivationPath, options);
28
- * ```
29
- */
30
- constructor({
31
- publicKey,
32
- derivationPath,
33
- ledgerClient,
34
- suiClient
35
- }: LedgerSignerOptions);
36
- /**
37
- * Retrieves the key scheme used by this signer.
38
- */
39
- getKeyScheme(): "ED25519";
40
- /**
41
- * Retrieves the public key associated with this signer.
42
- * @returns The Ed25519PublicKey instance.
43
- */
44
- getPublicKey(): Ed25519PublicKey;
45
- /**
46
- * Signs the provided transaction bytes.
47
- * @returns The signed transaction bytes and signature.
48
- */
49
- signTransaction(bytes: Uint8Array, bcsObjects?: Uint8Array[], resolution?: Resolution): Promise<SignatureWithBytes>;
50
- /**
51
- * Signs the provided personal message.
52
- * @returns The signed message bytes and signature.
53
- */
54
- signPersonalMessage(bytes: Uint8Array): Promise<SignatureWithBytes>;
55
- /**
56
- * Prepares the signer by fetching and setting the public key from a Ledger device.
57
- * It is recommended to initialize an `LedgerSigner` instance using this function.
58
- * @returns A promise that resolves once a `LedgerSigner` instance is prepared (public key is set).
59
- */
60
- static fromDerivationPath(derivationPath: string, ledgerClient: SuiLedgerClient, suiClient: ClientWithCoreApi): Promise<LedgerSigner>;
61
- /**
62
- * Generic signing is not supported by Ledger.
63
- * @throws Always throws an error indicating generic signing is unsupported.
64
- */
65
- sign(): never;
66
- /**
67
- * Generic signing is not supported by Ledger.
68
- * @throws Always throws an error indicating generic signing is unsupported.
69
- */
70
- signWithIntent(): never;
71
- }
72
- //#endregion
73
- export { LedgerSigner, LedgerSignerOptions, getInputObjects };
74
- //# sourceMappingURL=index.d.mts.map
1
+ export * from "@mysten/ledger-signer";
@@ -1,110 +1,3 @@
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";
1
+ export * from "@mysten/ledger-signer"
7
2
 
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
3
+ export { };
@@ -1,32 +1 @@
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
1
+ export * from "@mysten/webcrypto-signer";
@@ -1,70 +1,3 @@
1
- import { Signer } from "@mysten/sui/cryptography";
2
- import { p256 } from "@noble/curves/nist.js";
3
- import { Secp256r1PublicKey } from "@mysten/sui/keypairs/secp256r1";
1
+ export * from "@mysten/webcrypto-signer"
4
2
 
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
3
+ export { };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mysten/signers",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
4
4
  "description": "A collection of signers for various providers",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Mysten Labs <build@mystenlabs.com>",
@@ -32,13 +32,8 @@
32
32
  "CHANGELOG.md",
33
33
  "LICENSE",
34
34
  "README.md",
35
- "aws",
36
35
  "dist",
37
- "gcp",
38
- "ledger",
39
- "src",
40
- "src",
41
- "webcrypto"
36
+ "src"
42
37
  ],
43
38
  "repository": {
44
39
  "type": "git",
@@ -50,23 +45,19 @@
50
45
  "homepage": "https://github.com/MystenLabs/ts-sdks/tree/main/packages/signers#readme",
51
46
  "devDependencies": {
52
47
  "@types/node": "^25.0.8",
53
- "dotenv": "^17.2.3",
54
- "typescript": "^5.9.3",
55
- "vitest": "^4.0.17",
56
- "@mysten/sui": "^2.10.0"
48
+ "typescript": "^5.9.3"
57
49
  },
58
50
  "dependencies": {
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.8.0"
51
+ "@mysten/aws-kms-signer": "^0.1.2",
52
+ "@mysten/webcrypto-signer": "^0.1.2",
53
+ "@mysten/gcp-kms-signer": "^0.1.2",
54
+ "@mysten/ledger-signer": "^0.1.2"
64
55
  },
65
56
  "engines": {
66
57
  "node": ">=22"
67
58
  },
68
59
  "peerDependencies": {
69
- "@mysten/sui": "^2.10.0"
60
+ "@mysten/sui": "^2.16.2"
70
61
  },
71
62
  "scripts": {
72
63
  "clean": "rm -rf tsconfig.tsbuildinfo ./dist",
@@ -76,7 +67,6 @@
76
67
  "oxlint:check": "oxlint .",
77
68
  "oxlint:fix": "oxlint --fix",
78
69
  "lint": "pnpm run oxlint:check && pnpm run prettier:check",
79
- "lint:fix": "pnpm run oxlint:fix && pnpm run prettier:fix",
80
- "test": "vitest run"
70
+ "lint:fix": "pnpm run oxlint:fix && pnpm run prettier:fix"
81
71
  }
82
72
  }
package/src/aws/index.ts CHANGED
@@ -1,9 +1,4 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import type { AwsClientOptions } from './aws-client.js';
4
- import type { AwsKmsSignerOptions } from './aws-kms-signer.js';
5
- import { AwsKmsSigner } from './aws-kms-signer.js';
6
3
 
7
- export { AwsKmsSigner };
8
-
9
- export type { AwsKmsSignerOptions, AwsClientOptions };
4
+ export * from '@mysten/aws-kms-signer';
package/src/gcp/index.ts CHANGED
@@ -1,9 +1,4 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { GcpKmsSignerOptions } from './gcp-kms-client.js';
5
- import { GcpKmsSigner } from './gcp-kms-client.js';
6
-
7
- export { GcpKmsSigner };
8
-
9
- export type { GcpKmsSignerOptions };
4
+ export * from '@mysten/gcp-kms-signer';
@@ -1,163 +1,4 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type SuiLedgerClient from '@mysten/ledgerjs-hw-app-sui';
5
- import type { ClientWithCoreApi } from '@mysten/sui/client';
6
- import type { SignatureWithBytes } from '@mysten/sui/cryptography';
7
- import { messageWithIntent, Signer, toSerializedSignature } from '@mysten/sui/cryptography';
8
- import { Ed25519PublicKey } from '@mysten/sui/keypairs/ed25519';
9
- import { Transaction } from '@mysten/sui/transactions';
10
- import { toBase64 } from '@mysten/sui/utils';
11
-
12
- import { bcs } from '@mysten/sui/bcs';
13
- import { getInputObjects } from './objects.js';
14
- import type { Resolution } from '@mysten/ledgerjs-hw-app-sui';
15
-
16
- export { getInputObjects } from './objects.js';
17
-
18
- /**
19
- * Configuration options for initializing the LedgerSigner.
20
- */
21
- export interface LedgerSignerOptions {
22
- publicKey: Ed25519PublicKey;
23
- derivationPath: string;
24
- ledgerClient: SuiLedgerClient;
25
- suiClient: ClientWithCoreApi;
26
- }
27
-
28
- /**
29
- * Ledger integrates with the Sui blockchain to provide signing capabilities using Ledger devices.
30
- */
31
- export class LedgerSigner extends Signer {
32
- #derivationPath: string;
33
- #publicKey: Ed25519PublicKey;
34
- #ledgerClient: SuiLedgerClient;
35
- #suiClient: ClientWithCoreApi;
36
-
37
- /**
38
- * Creates an instance of LedgerSigner. It's expected to call the static `fromDerivationPath` method to create an instance.
39
- * @example
40
- * ```
41
- * const signer = await LedgerSigner.fromDerivationPath(derivationPath, options);
42
- * ```
43
- */
44
- constructor({ publicKey, derivationPath, ledgerClient, suiClient }: LedgerSignerOptions) {
45
- super();
46
- this.#publicKey = publicKey;
47
- this.#derivationPath = derivationPath;
48
- this.#ledgerClient = ledgerClient;
49
- this.#suiClient = suiClient;
50
- }
51
-
52
- /**
53
- * Retrieves the key scheme used by this signer.
54
- */
55
- override getKeyScheme() {
56
- return 'ED25519' as const;
57
- }
58
-
59
- /**
60
- * Retrieves the public key associated with this signer.
61
- * @returns The Ed25519PublicKey instance.
62
- */
63
- override getPublicKey() {
64
- return this.#publicKey;
65
- }
66
-
67
- /**
68
- * Signs the provided transaction bytes.
69
- * @returns The signed transaction bytes and signature.
70
- */
71
- override async signTransaction(
72
- bytes: Uint8Array,
73
- bcsObjects?: Uint8Array[],
74
- resolution?: Resolution,
75
- ): Promise<SignatureWithBytes> {
76
- const transactionOptions = bcsObjects
77
- ? { bcsObjects }
78
- : await getInputObjects(Transaction.from(bytes), this.#suiClient).catch(() => ({
79
- // Fail gracefully so network errors or serialization issues don't break transaction signing:
80
- bcsObjects: [],
81
- }));
82
-
83
- const intentMessage = messageWithIntent('TransactionData', bytes);
84
- const { signature } = await this.#ledgerClient.signTransaction(
85
- this.#derivationPath,
86
- intentMessage,
87
- transactionOptions,
88
- resolution,
89
- );
90
-
91
- return {
92
- bytes: toBase64(bytes),
93
- signature: toSerializedSignature({
94
- signature,
95
- signatureScheme: this.getKeyScheme(),
96
- publicKey: this.#publicKey,
97
- }),
98
- };
99
- }
100
-
101
- /**
102
- * Signs the provided personal message.
103
- * @returns The signed message bytes and signature.
104
- */
105
- override async signPersonalMessage(bytes: Uint8Array): Promise<SignatureWithBytes> {
106
- const intentMessage = messageWithIntent(
107
- 'PersonalMessage',
108
- bcs.byteVector().serialize(bytes).toBytes(),
109
- );
110
- const { signature } = await this.#ledgerClient.signTransaction(
111
- this.#derivationPath,
112
- intentMessage,
113
- );
114
-
115
- return {
116
- bytes: toBase64(bytes),
117
- signature: toSerializedSignature({
118
- signature,
119
- signatureScheme: this.getKeyScheme(),
120
- publicKey: this.#publicKey,
121
- }),
122
- };
123
- }
124
-
125
- /**
126
- * Prepares the signer by fetching and setting the public key from a Ledger device.
127
- * It is recommended to initialize an `LedgerSigner` instance using this function.
128
- * @returns A promise that resolves once a `LedgerSigner` instance is prepared (public key is set).
129
- */
130
- static async fromDerivationPath(
131
- derivationPath: string,
132
- ledgerClient: SuiLedgerClient,
133
- suiClient: ClientWithCoreApi,
134
- ) {
135
- const { publicKey } = await ledgerClient.getPublicKey(derivationPath);
136
- if (!publicKey) {
137
- throw new Error('Failed to get public key from Ledger.');
138
- }
139
-
140
- return new LedgerSigner({
141
- derivationPath,
142
- publicKey: new Ed25519PublicKey(publicKey),
143
- ledgerClient,
144
- suiClient,
145
- });
146
- }
147
-
148
- /**
149
- * Generic signing is not supported by Ledger.
150
- * @throws Always throws an error indicating generic signing is unsupported.
151
- */
152
- override sign(): never {
153
- throw new Error('Ledger Signer does not support generic signing.');
154
- }
155
-
156
- /**
157
- * Generic signing is not supported by Ledger.
158
- * @throws Always throws an error indicating generic signing is unsupported.
159
- */
160
- override signWithIntent(): never {
161
- throw new Error('Ledger Signer does not support generic signing.');
162
- }
163
- }
4
+ export * from '@mysten/ledger-signer';