@mysten/signers 0.5.10 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/cjs/ledger/index.d.ts +2 -1
- package/dist/cjs/ledger/index.js +4 -6
- package/dist/cjs/ledger/index.js.map +2 -2
- package/dist/esm/ledger/index.d.ts +2 -1
- package/dist/esm/ledger/index.js +4 -6
- package/dist/esm/ledger/index.js.map +2 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/ledger/index.ts +13 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @mysten/signers
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 434381d: Add support for fetching tokens from the CAL (crypto asset list) for clear signing
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [434381d]
|
|
12
|
+
- @mysten/ledgerjs-hw-app-sui@0.7.0
|
|
13
|
+
|
|
3
14
|
## 0.5.10
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
@@ -3,6 +3,7 @@ import type { SuiClient } from '@mysten/sui/client';
|
|
|
3
3
|
import type { SignatureWithBytes } from '@mysten/sui/cryptography';
|
|
4
4
|
import { Signer } from '@mysten/sui/cryptography';
|
|
5
5
|
import { Ed25519PublicKey } from '@mysten/sui/keypairs/ed25519';
|
|
6
|
+
import type { Resolution } from '@mysten/ledgerjs-hw-app-sui';
|
|
6
7
|
export { SuiMoveObject } from './bcs.js';
|
|
7
8
|
export { getInputObjects } from './objects.js';
|
|
8
9
|
/**
|
|
@@ -40,7 +41,7 @@ export declare class LedgerSigner extends Signer {
|
|
|
40
41
|
* Signs the provided transaction bytes.
|
|
41
42
|
* @returns The signed transaction bytes and signature.
|
|
42
43
|
*/
|
|
43
|
-
signTransaction(bytes: Uint8Array): Promise<SignatureWithBytes>;
|
|
44
|
+
signTransaction(bytes: Uint8Array, bcsObjects?: Uint8Array[], resolution?: Resolution): Promise<SignatureWithBytes>;
|
|
44
45
|
/**
|
|
45
46
|
* Signs the provided personal message.
|
|
46
47
|
* @returns The signed message bytes and signature.
|
package/dist/cjs/ledger/index.js
CHANGED
|
@@ -75,11 +75,8 @@ const _LedgerSigner = class _LedgerSigner extends import_cryptography.Signer {
|
|
|
75
75
|
* Signs the provided transaction bytes.
|
|
76
76
|
* @returns The signed transaction bytes and signature.
|
|
77
77
|
*/
|
|
78
|
-
async signTransaction(bytes) {
|
|
79
|
-
const transactionOptions = await (0, import_objects.getInputObjects)(
|
|
80
|
-
import_transactions.Transaction.from(bytes),
|
|
81
|
-
__privateGet(this, _suiClient)
|
|
82
|
-
).catch(() => ({
|
|
78
|
+
async signTransaction(bytes, bcsObjects, resolution) {
|
|
79
|
+
const transactionOptions = bcsObjects ? { bcsObjects } : await (0, import_objects.getInputObjects)(import_transactions.Transaction.from(bytes), __privateGet(this, _suiClient)).catch(() => ({
|
|
83
80
|
// Fail gracefully so network errors or serialization issues don't break transaction signing:
|
|
84
81
|
bcsObjects: []
|
|
85
82
|
}));
|
|
@@ -87,7 +84,8 @@ const _LedgerSigner = class _LedgerSigner extends import_cryptography.Signer {
|
|
|
87
84
|
const { signature } = await __privateGet(this, _ledgerClient).signTransaction(
|
|
88
85
|
__privateGet(this, _derivationPath),
|
|
89
86
|
intentMessage,
|
|
90
|
-
transactionOptions
|
|
87
|
+
transactionOptions,
|
|
88
|
+
resolution
|
|
91
89
|
);
|
|
92
90
|
return {
|
|
93
91
|
bytes: (0, import_utils.toBase64)(bytes),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/ledger/index.ts"],
|
|
4
|
-
"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 { SuiClient } 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';\n\nexport { SuiMoveObject } from './bcs.js';\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: SuiClient;\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: SuiClient;\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(
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,0BAAiE;AACjE,qBAAiC;AACjC,0BAA4B;AAC5B,mBAAyB;AAEzB,iBAAoB;AACpB,qBAAgC;
|
|
4
|
+
"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 { SuiClient } 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 { SuiMoveObject } from './bcs.js';\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: SuiClient;\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: SuiClient;\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: SuiClient,\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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,0BAAiE;AACjE,qBAAiC;AACjC,0BAA4B;AAC5B,mBAAyB;AAEzB,iBAAoB;AACpB,qBAAgC;AAGhC,IAAAA,cAA8B;AAC9B,IAAAC,kBAAgC;AAhBhC;AA+BO,MAAM,gBAAN,MAAM,sBAAqB,2BAAO;AAAA;AAAA;AAAA;AAAA;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ACA,iBAAiB,KAAK,aAAa;AAAA,QACnC,WAAW,mBAAK;AAAA,MACjB,CAAC;AAAA,IACF;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,aAAa,mBACZ,gBACA,cACA,WACC;AACD,UAAM,EAAE,UAAU,IAAI,MAAM,aAAa,aAAa,cAAc;AACpE,QAAI,CAAC,WAAW;AACf,YAAM,IAAI,MAAM,uCAAuC;AAAA,IACxD;AAEA,WAAO,IAAI,cAAa;AAAA,MACvB;AAAA,MACA,WAAW,IAAI,gCAAiB,SAAS;AAAA,MACzC;AAAA,MACA;AAAA,IACD,CAAC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMS,OAAc;AACtB,UAAM,IAAI,MAAM,iDAAiD;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMS,iBAAwB;AAChC,UAAM,IAAI,MAAM,iDAAiD;AAAA,EAClE;AACD;AAnIC;AACA;AACA;AACA;AAJM,IAAM,eAAN;",
|
|
6
6
|
"names": ["import_bcs", "import_objects"]
|
|
7
7
|
}
|
|
@@ -3,6 +3,7 @@ import type { SuiClient } from '@mysten/sui/client';
|
|
|
3
3
|
import type { SignatureWithBytes } from '@mysten/sui/cryptography';
|
|
4
4
|
import { Signer } from '@mysten/sui/cryptography';
|
|
5
5
|
import { Ed25519PublicKey } from '@mysten/sui/keypairs/ed25519';
|
|
6
|
+
import type { Resolution } from '@mysten/ledgerjs-hw-app-sui';
|
|
6
7
|
export { SuiMoveObject } from './bcs.js';
|
|
7
8
|
export { getInputObjects } from './objects.js';
|
|
8
9
|
/**
|
|
@@ -40,7 +41,7 @@ export declare class LedgerSigner extends Signer {
|
|
|
40
41
|
* Signs the provided transaction bytes.
|
|
41
42
|
* @returns The signed transaction bytes and signature.
|
|
42
43
|
*/
|
|
43
|
-
signTransaction(bytes: Uint8Array): Promise<SignatureWithBytes>;
|
|
44
|
+
signTransaction(bytes: Uint8Array, bcsObjects?: Uint8Array[], resolution?: Resolution): Promise<SignatureWithBytes>;
|
|
44
45
|
/**
|
|
45
46
|
* Signs the provided personal message.
|
|
46
47
|
* @returns The signed message bytes and signature.
|
package/dist/esm/ledger/index.js
CHANGED
|
@@ -50,11 +50,8 @@ const _LedgerSigner = class _LedgerSigner extends Signer {
|
|
|
50
50
|
* Signs the provided transaction bytes.
|
|
51
51
|
* @returns The signed transaction bytes and signature.
|
|
52
52
|
*/
|
|
53
|
-
async signTransaction(bytes) {
|
|
54
|
-
const transactionOptions = await getInputObjects(
|
|
55
|
-
Transaction.from(bytes),
|
|
56
|
-
__privateGet(this, _suiClient)
|
|
57
|
-
).catch(() => ({
|
|
53
|
+
async signTransaction(bytes, bcsObjects, resolution) {
|
|
54
|
+
const transactionOptions = bcsObjects ? { bcsObjects } : await getInputObjects(Transaction.from(bytes), __privateGet(this, _suiClient)).catch(() => ({
|
|
58
55
|
// Fail gracefully so network errors or serialization issues don't break transaction signing:
|
|
59
56
|
bcsObjects: []
|
|
60
57
|
}));
|
|
@@ -62,7 +59,8 @@ const _LedgerSigner = class _LedgerSigner extends Signer {
|
|
|
62
59
|
const { signature } = await __privateGet(this, _ledgerClient).signTransaction(
|
|
63
60
|
__privateGet(this, _derivationPath),
|
|
64
61
|
intentMessage,
|
|
65
|
-
transactionOptions
|
|
62
|
+
transactionOptions,
|
|
63
|
+
resolution
|
|
66
64
|
);
|
|
67
65
|
return {
|
|
68
66
|
bytes: toBase64(bytes),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/ledger/index.ts"],
|
|
4
|
-
"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 { SuiClient } 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';\n\nexport { SuiMoveObject } from './bcs.js';\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: SuiClient;\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: SuiClient;\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(
|
|
5
|
-
"mappings": ";;;;;;;AAAA;AAMA,SAAS,mBAAmB,QAAQ,6BAA6B;AACjE,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAEzB,SAAS,WAAW;AACpB,SAAS,uBAAuB;
|
|
4
|
+
"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 { SuiClient } 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 { SuiMoveObject } from './bcs.js';\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: SuiClient;\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: SuiClient;\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: SuiClient,\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"],
|
|
5
|
+
"mappings": ";;;;;;;AAAA;AAMA,SAAS,mBAAmB,QAAQ,6BAA6B;AACjE,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAEzB,SAAS,WAAW;AACpB,SAAS,uBAAuB;AAGhC,SAAS,qBAAqB;AAC9B,SAAS,mBAAAA,wBAAuB;AAezB,MAAM,gBAAN,MAAM,sBAAqB,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaxC,YAAY,EAAE,WAAW,gBAAgB,cAAc,UAAU,GAAwB;AACxF,UAAM;AAbP;AACA;AACA;AACA;AAWC,uBAAK,YAAa;AAClB,uBAAK,iBAAkB;AACvB,uBAAK,eAAgB;AACrB,uBAAK,YAAa;AAAA,EACnB;AAAA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