@mysten/signers 0.1.17 → 0.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @mysten/signers
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [4d13ef8]
8
+ - Updated dependencies [4d13ef8]
9
+ - @mysten/sui@1.27.0
10
+
11
+ ## 0.2.0
12
+
13
+ ### Minor Changes
14
+
15
+ - 156ae13: Add new LedgerSigner class for signing transactions with a Ledger hardware wallet
16
+
17
+ ### Patch Changes
18
+
19
+ - 7ba32a4: update dependencies
20
+ - Updated dependencies [7ba32a4]
21
+ - Updated dependencies [156ae13]
22
+ - Updated dependencies [156ae13]
23
+ - @mysten/ledgerjs-hw-app-sui@0.5.0
24
+ - @mysten/sui@1.26.1
25
+
3
26
  ## 0.1.17
4
27
 
5
28
  ### Patch Changes
package/README.md CHANGED
@@ -5,18 +5,24 @@ Management Services (KMS) like AWS KMS and GCP KMS.
5
5
 
6
6
  ## Table of Contents
7
7
 
8
- - [AWS KMS Signer](#aws-kms-signer)
9
- - [Usage](#usage)
10
- - [API](#api)
11
- - [fromKeyId](#fromkeyid)
12
- - [Parameters](#parameters)
13
- - [Examples](#examples)
14
- - [GCP KMS Signer](#gcp-kms-signer)
15
- - [Usage](#usage-1)
16
- - [API](#api-1)
17
- - [fromOptions](#fromoptions)
18
- - [Parameters](#parameters-1)
19
- - [Examples](#examples-1)
8
+ - [Sui KMS Signers](#sui-kms-signers)
9
+ - [Table of Contents](#table-of-contents)
10
+ - [AWS KMS Signer](#aws-kms-signer)
11
+ - [Usage](#usage)
12
+ - [API](#api)
13
+ - [fromKeyId](#fromkeyid)
14
+ - [Parameters](#parameters)
15
+ - [Examples](#examples)
16
+ - [GCP KMS Signer](#gcp-kms-signer)
17
+ - [Usage](#usage-1)
18
+ - [fromOptions](#fromoptions)
19
+ - [Parameters](#parameters-1)
20
+ - [Examples](#examples-1)
21
+ - [Ledger Signer](#ledger-signer)
22
+ - [Usage](#usage-2)
23
+ - [fromDerivationPath](#fromderivationpath)
24
+ - [Parameters](#parameters-2)
25
+ - [Examples](#examples-2)
20
26
 
21
27
  ## AWS KMS Signer
22
28
 
@@ -140,3 +146,55 @@ const { signature } = await signer.signPersonalMessage(messageBytes);
140
146
  const isValid = await publicKey.verifyPersonalMessage(messageBytes, signature);
141
147
  console.log(isValid); // Should print true if the signature is valid
142
148
  ```
149
+
150
+ ## Ledger Signer
151
+
152
+ The Ledger Signer allows you to leverage a Ledger hardware wallet to sign Sui transactions.
153
+
154
+ ### Usage
155
+
156
+ #### fromDerivationPath
157
+
158
+ Creates a Ledger signer from the provided options. This method initializes the signer with the
159
+ necessary configuration, allowing it to interact with a Ledger hardare wallet to perform
160
+ cryptographic operations.
161
+
162
+ ##### Parameters
163
+
164
+ - `options`
165
+ **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** An
166
+ object containing GCP credentials and configuration.
167
+ - `projectId`
168
+ **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
169
+ The GCP project ID.
170
+
171
+ ##### Examples
172
+
173
+ ```typescript
174
+ import Transport from '@ledgerhq/hw-transport-node-hid';
175
+ import SuiLedgerClient from '@mysten/ledgerjs-hw-app-sui';
176
+ import { LedgerSigner } from '@mysten/signers/ledger';
177
+ import { SuiClient } from '@mysten/sui/client';
178
+ import { Transaction } from '@mysten/sui/transactions';
179
+
180
+ const transport = await Transport.open(undefined);
181
+ const ledgerClient = new SuiLedgerClient(transport);
182
+ const suiClient = new SuiClient({ url: getNetworkUrl('testnet') });
183
+
184
+ const signer = await LedgerSigner.fromDerivationPath({
185
+ derivationPath: "m/44'/784'/0'/0'/0'",
186
+ ledgerClient,
187
+ suiClient,
188
+ });
189
+
190
+ // Log the Sui address:
191
+ console.log(signer.toSuiAddress());
192
+
193
+ // Define a test transaction:
194
+ const testTransaction = new Transaction();
195
+ const transactionBytes = await testTransaction.build();
196
+
197
+ // Sign a test transaction:
198
+ const { signature } = await signer.signTransaction(transactionBytes);
199
+ console.log(signature);
200
+ ```
@@ -0,0 +1,27 @@
1
+ import type { ObjectOwner } from '@mysten/sui/client';
2
+ export declare const SuiMoveObject: import("@mysten/sui/bcs").BcsType<{
3
+ data: {
4
+ MoveObject: {
5
+ type: any;
6
+ hasPublicTransfer: boolean;
7
+ version: string;
8
+ contents: any;
9
+ };
10
+ $kind: "MoveObject";
11
+ };
12
+ owner: any;
13
+ previousTransaction: string;
14
+ storageRebate: string;
15
+ }, {
16
+ data: {
17
+ MoveObject: {
18
+ type: string;
19
+ hasPublicTransfer: boolean;
20
+ version: string | number | bigint;
21
+ contents: string;
22
+ };
23
+ };
24
+ owner: ObjectOwner;
25
+ previousTransaction: string;
26
+ storageRebate: string | number | bigint;
27
+ }>;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var bcs_exports = {};
20
+ __export(bcs_exports, {
21
+ SuiMoveObject: () => SuiMoveObject
22
+ });
23
+ module.exports = __toCommonJS(bcs_exports);
24
+ var import_bcs = require("@mysten/sui/bcs");
25
+ var import_utils = require("@mysten/sui/utils");
26
+ const SUI_FRAMEWORK_ADDRESS = (0, import_utils.normalizeSuiAddress)("0x2");
27
+ const SUI_SYSTEM_ADDRESS = (0, import_utils.normalizeSuiAddress)("0x3");
28
+ const MoveObjectType = import_bcs.bcs.enum("MoveObjectType", {
29
+ Other: import_bcs.bcs.StructTag,
30
+ GasCoin: null,
31
+ StakedSui: null,
32
+ Coin: import_bcs.bcs.TypeTag
33
+ });
34
+ const SuiMoveObject = import_bcs.bcs.struct("SuiMoveObject", {
35
+ data: import_bcs.bcs.enum("Data", {
36
+ MoveObject: import_bcs.bcs.struct("MoveObject", {
37
+ type: MoveObjectType.transform({
38
+ input: (objectType) => {
39
+ const structTag = (0, import_utils.parseStructTag)(objectType);
40
+ if (structTag.address === SUI_FRAMEWORK_ADDRESS && structTag.module === "coin" && structTag.name === "Coin" && typeof structTag.typeParams[0] === "object") {
41
+ const innerStructTag = structTag.typeParams[0];
42
+ if (innerStructTag.address === SUI_FRAMEWORK_ADDRESS && innerStructTag.module === "sui" && innerStructTag.name === "SUI") {
43
+ return { GasCoin: true, $kind: "GasCoin" };
44
+ }
45
+ return { Coin: (0, import_utils.normalizeStructTag)(innerStructTag), $kind: "Coin" };
46
+ } else if (structTag.address === SUI_SYSTEM_ADDRESS && structTag.module === "staking_pool" && structTag.name === "StakedSui") {
47
+ return { StakedSui: true, $kind: "StakedSui" };
48
+ }
49
+ return {
50
+ Other: {
51
+ ...structTag,
52
+ typeParams: structTag.typeParams.map((typeParam) => {
53
+ return import_bcs.TypeTagSerializer.parseFromStr((0, import_utils.normalizeStructTag)(typeParam));
54
+ })
55
+ },
56
+ $kind: "Other"
57
+ };
58
+ }
59
+ }),
60
+ hasPublicTransfer: import_bcs.bcs.bool(),
61
+ version: import_bcs.bcs.u64(),
62
+ contents: import_bcs.bcs.byteVector().transform({ input: import_utils.fromBase64 })
63
+ })
64
+ }),
65
+ owner: import_bcs.bcs.Owner.transform({
66
+ input: (objectOwner) => {
67
+ if (objectOwner === "Immutable") {
68
+ return { Immutable: null };
69
+ } else if ("Shared" in objectOwner) {
70
+ return { Shared: { initialSharedVersion: objectOwner.Shared.initial_shared_version } };
71
+ } else if ("ConsensusV2" in objectOwner) {
72
+ return {
73
+ ConsensusV2: {
74
+ authenticator: objectOwner.ConsensusV2.authenticator,
75
+ startVersion: objectOwner.ConsensusV2.start_version
76
+ }
77
+ };
78
+ }
79
+ return objectOwner;
80
+ }
81
+ }),
82
+ previousTransaction: import_bcs.bcs.ObjectDigest,
83
+ storageRebate: import_bcs.bcs.u64()
84
+ });
85
+ //# sourceMappingURL=bcs.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/ledger/bcs.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs, TypeTagSerializer } from '@mysten/sui/bcs';\nimport type { ObjectOwner } from '@mysten/sui/client';\nimport {\n\tfromBase64,\n\tnormalizeStructTag,\n\tnormalizeSuiAddress,\n\tparseStructTag,\n} from '@mysten/sui/utils';\n\nconst SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress('0x2');\nconst SUI_SYSTEM_ADDRESS = normalizeSuiAddress('0x3');\n\nconst MoveObjectType = bcs.enum('MoveObjectType', {\n\tOther: bcs.StructTag,\n\tGasCoin: null,\n\tStakedSui: null,\n\tCoin: bcs.TypeTag,\n});\n\nexport const SuiMoveObject = bcs.struct('SuiMoveObject', {\n\tdata: bcs.enum('Data', {\n\t\tMoveObject: bcs.struct('MoveObject', {\n\t\t\ttype: MoveObjectType.transform({\n\t\t\t\tinput: (objectType: string): typeof MoveObjectType.$inferType => {\n\t\t\t\t\tconst structTag = parseStructTag(objectType);\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tstructTag.address === SUI_FRAMEWORK_ADDRESS &&\n\t\t\t\t\t\tstructTag.module === 'coin' &&\n\t\t\t\t\t\tstructTag.name === 'Coin' &&\n\t\t\t\t\t\ttypeof structTag.typeParams[0] === 'object'\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst innerStructTag = structTag.typeParams[0];\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tinnerStructTag.address === SUI_FRAMEWORK_ADDRESS &&\n\t\t\t\t\t\t\tinnerStructTag.module === 'sui' &&\n\t\t\t\t\t\t\tinnerStructTag.name === 'SUI'\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn { GasCoin: true, $kind: 'GasCoin' };\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn { Coin: normalizeStructTag(innerStructTag), $kind: 'Coin' };\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tstructTag.address === SUI_SYSTEM_ADDRESS &&\n\t\t\t\t\t\tstructTag.module === 'staking_pool' &&\n\t\t\t\t\t\tstructTag.name === 'StakedSui'\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn { StakedSui: true, $kind: 'StakedSui' };\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\tOther: {\n\t\t\t\t\t\t\t...structTag,\n\t\t\t\t\t\t\ttypeParams: structTag.typeParams.map((typeParam) => {\n\t\t\t\t\t\t\t\treturn TypeTagSerializer.parseFromStr(normalizeStructTag(typeParam));\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t},\n\t\t\t\t\t\t$kind: 'Other',\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t}),\n\t\t\thasPublicTransfer: bcs.bool(),\n\t\t\tversion: bcs.u64(),\n\t\t\tcontents: bcs.byteVector().transform({ input: fromBase64 }),\n\t\t}),\n\t}),\n\towner: bcs.Owner.transform({\n\t\tinput: (objectOwner: ObjectOwner) => {\n\t\t\tif (objectOwner === 'Immutable') {\n\t\t\t\treturn { Immutable: null };\n\t\t\t} else if ('Shared' in objectOwner) {\n\t\t\t\treturn { Shared: { initialSharedVersion: objectOwner.Shared.initial_shared_version } };\n\t\t\t} else if ('ConsensusV2' in objectOwner) {\n\t\t\t\treturn {\n\t\t\t\t\tConsensusV2: {\n\t\t\t\t\t\tauthenticator: objectOwner.ConsensusV2.authenticator,\n\t\t\t\t\t\tstartVersion: objectOwner.ConsensusV2.start_version,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn objectOwner;\n\t\t},\n\t}),\n\tpreviousTransaction: bcs.ObjectDigest,\n\tstorageRebate: bcs.u64(),\n});\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAuC;AAEvC,mBAKO;AAEP,MAAM,4BAAwB,kCAAoB,KAAK;AACvD,MAAM,yBAAqB,kCAAoB,KAAK;AAEpD,MAAM,iBAAiB,eAAI,KAAK,kBAAkB;AAAA,EACjD,OAAO,eAAI;AAAA,EACX,SAAS;AAAA,EACT,WAAW;AAAA,EACX,MAAM,eAAI;AACX,CAAC;AAEM,MAAM,gBAAgB,eAAI,OAAO,iBAAiB;AAAA,EACxD,MAAM,eAAI,KAAK,QAAQ;AAAA,IACtB,YAAY,eAAI,OAAO,cAAc;AAAA,MACpC,MAAM,eAAe,UAAU;AAAA,QAC9B,OAAO,CAAC,eAAyD;AAChE,gBAAM,gBAAY,6BAAe,UAAU;AAE3C,cACC,UAAU,YAAY,yBACtB,UAAU,WAAW,UACrB,UAAU,SAAS,UACnB,OAAO,UAAU,WAAW,CAAC,MAAM,UAClC;AACD,kBAAM,iBAAiB,UAAU,WAAW,CAAC;AAC7C,gBACC,eAAe,YAAY,yBAC3B,eAAe,WAAW,SAC1B,eAAe,SAAS,OACvB;AACD,qBAAO,EAAE,SAAS,MAAM,OAAO,UAAU;AAAA,YAC1C;AACA,mBAAO,EAAE,UAAM,iCAAmB,cAAc,GAAG,OAAO,OAAO;AAAA,UAClE,WACC,UAAU,YAAY,sBACtB,UAAU,WAAW,kBACrB,UAAU,SAAS,aAClB;AACD,mBAAO,EAAE,WAAW,MAAM,OAAO,YAAY;AAAA,UAC9C;AACA,iBAAO;AAAA,YACN,OAAO;AAAA,cACN,GAAG;AAAA,cACH,YAAY,UAAU,WAAW,IAAI,CAAC,cAAc;AACnD,uBAAO,6BAAkB,iBAAa,iCAAmB,SAAS,CAAC;AAAA,cACpE,CAAC;AAAA,YACF;AAAA,YACA,OAAO;AAAA,UACR;AAAA,QACD;AAAA,MACD,CAAC;AAAA,MACD,mBAAmB,eAAI,KAAK;AAAA,MAC5B,SAAS,eAAI,IAAI;AAAA,MACjB,UAAU,eAAI,WAAW,EAAE,UAAU,EAAE,OAAO,wBAAW,CAAC;AAAA,IAC3D,CAAC;AAAA,EACF,CAAC;AAAA,EACD,OAAO,eAAI,MAAM,UAAU;AAAA,IAC1B,OAAO,CAAC,gBAA6B;AACpC,UAAI,gBAAgB,aAAa;AAChC,eAAO,EAAE,WAAW,KAAK;AAAA,MAC1B,WAAW,YAAY,aAAa;AACnC,eAAO,EAAE,QAAQ,EAAE,sBAAsB,YAAY,OAAO,uBAAuB,EAAE;AAAA,MACtF,WAAW,iBAAiB,aAAa;AACxC,eAAO;AAAA,UACN,aAAa;AAAA,YACZ,eAAe,YAAY,YAAY;AAAA,YACvC,cAAc,YAAY,YAAY;AAAA,UACvC;AAAA,QACD;AAAA,MACD;AACA,aAAO;AAAA,IACR;AAAA,EACD,CAAC;AAAA,EACD,qBAAqB,eAAI;AAAA,EACzB,eAAe,eAAI,IAAI;AACxB,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,63 @@
1
+ import type SuiLedgerClient from '@mysten/ledgerjs-hw-app-sui';
2
+ import type { SuiClient } from '@mysten/sui/client';
3
+ import type { SignatureWithBytes } from '@mysten/sui/cryptography';
4
+ import { Signer } from '@mysten/sui/cryptography';
5
+ import { Ed25519PublicKey } from '@mysten/sui/keypairs/ed25519';
6
+ /**
7
+ * Configuration options for initializing the LedgerSigner.
8
+ */
9
+ export interface LedgerSignerOptions {
10
+ publicKey: Ed25519PublicKey;
11
+ derivationPath: string;
12
+ ledgerClient: SuiLedgerClient;
13
+ suiClient: SuiClient;
14
+ }
15
+ /**
16
+ * Ledger integrates with the Sui blockchain to provide signing capabilities using Ledger devices.
17
+ */
18
+ export declare class LedgerSigner extends Signer {
19
+ #private;
20
+ /**
21
+ * Creates an instance of LedgerSigner. It's expected to call the static `fromDerivationPath` method to create an instance.
22
+ * @example
23
+ * ```
24
+ * const signer = await LedgerSigner.fromDerivationPath(derivationPath, options);
25
+ * ```
26
+ */
27
+ constructor({ publicKey, derivationPath, ledgerClient, suiClient }: LedgerSignerOptions);
28
+ /**
29
+ * Retrieves the key scheme used by this signer.
30
+ */
31
+ getKeyScheme(): "ED25519";
32
+ /**
33
+ * Retrieves the public key associated with this signer.
34
+ * @returns The Ed25519PublicKey instance.
35
+ */
36
+ getPublicKey(): Ed25519PublicKey;
37
+ /**
38
+ * Signs the provided transaction bytes.
39
+ * @returns The signed transaction bytes and signature.
40
+ */
41
+ signTransaction(bytes: Uint8Array): Promise<SignatureWithBytes>;
42
+ /**
43
+ * Signs the provided personal message.
44
+ * @returns The signed message bytes and signature.
45
+ */
46
+ signPersonalMessage(bytes: Uint8Array): Promise<SignatureWithBytes>;
47
+ /**
48
+ * Prepares the signer by fetching and setting the public key from a Ledger device.
49
+ * It is recommended to initialize an `LedgerSigner` instance using this function.
50
+ * @returns A promise that resolves once a `LedgerSigner` instance is prepared (public key is set).
51
+ */
52
+ static fromDerivationPath(derivationPath: string, ledgerClient: SuiLedgerClient, suiClient: SuiClient): Promise<LedgerSigner>;
53
+ /**
54
+ * Generic signing is not supported by Ledger.
55
+ * @throws Always throws an error indicating generic signing is unsupported.
56
+ */
57
+ sign(): never;
58
+ /**
59
+ * Generic signing is not supported by Ledger.
60
+ * @throws Always throws an error indicating generic signing is unsupported.
61
+ */
62
+ signWithIntent(): never;
63
+ }
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __typeError = (msg) => {
7
+ throw TypeError(msg);
8
+ };
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
23
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
24
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
25
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
26
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
27
+ var ledger_exports = {};
28
+ __export(ledger_exports, {
29
+ LedgerSigner: () => LedgerSigner
30
+ });
31
+ module.exports = __toCommonJS(ledger_exports);
32
+ var import_cryptography = require("@mysten/sui/cryptography");
33
+ var import_ed25519 = require("@mysten/sui/keypairs/ed25519");
34
+ var import_transactions = require("@mysten/sui/transactions");
35
+ var import_utils = require("@mysten/sui/utils");
36
+ var import_bcs = require("./bcs.js");
37
+ var _derivationPath, _publicKey, _ledgerClient, _suiClient, _LedgerSigner_instances, getClearSigningOptions_fn;
38
+ const _LedgerSigner = class _LedgerSigner extends import_cryptography.Signer {
39
+ /**
40
+ * Creates an instance of LedgerSigner. It's expected to call the static `fromDerivationPath` method to create an instance.
41
+ * @example
42
+ * ```
43
+ * const signer = await LedgerSigner.fromDerivationPath(derivationPath, options);
44
+ * ```
45
+ */
46
+ constructor({ publicKey, derivationPath, ledgerClient, suiClient }) {
47
+ super();
48
+ __privateAdd(this, _LedgerSigner_instances);
49
+ __privateAdd(this, _derivationPath);
50
+ __privateAdd(this, _publicKey);
51
+ __privateAdd(this, _ledgerClient);
52
+ __privateAdd(this, _suiClient);
53
+ __privateSet(this, _publicKey, publicKey);
54
+ __privateSet(this, _derivationPath, derivationPath);
55
+ __privateSet(this, _ledgerClient, ledgerClient);
56
+ __privateSet(this, _suiClient, suiClient);
57
+ }
58
+ /**
59
+ * Retrieves the key scheme used by this signer.
60
+ */
61
+ getKeyScheme() {
62
+ return "ED25519";
63
+ }
64
+ /**
65
+ * Retrieves the public key associated with this signer.
66
+ * @returns The Ed25519PublicKey instance.
67
+ */
68
+ getPublicKey() {
69
+ return __privateGet(this, _publicKey);
70
+ }
71
+ /**
72
+ * Signs the provided transaction bytes.
73
+ * @returns The signed transaction bytes and signature.
74
+ */
75
+ async signTransaction(bytes) {
76
+ const transactionOptions = await __privateMethod(this, _LedgerSigner_instances, getClearSigningOptions_fn).call(this, bytes).catch(() => ({
77
+ // Fail gracefully so network errors or serialization issues don't break transaction signing:
78
+ bcsObjects: []
79
+ }));
80
+ const intentMessage = (0, import_cryptography.messageWithIntent)("TransactionData", bytes);
81
+ const { signature } = await __privateGet(this, _ledgerClient).signTransaction(
82
+ __privateGet(this, _derivationPath),
83
+ intentMessage,
84
+ transactionOptions
85
+ );
86
+ return {
87
+ bytes: (0, import_utils.toBase64)(bytes),
88
+ signature: (0, import_cryptography.toSerializedSignature)({
89
+ signature,
90
+ signatureScheme: this.getKeyScheme(),
91
+ publicKey: __privateGet(this, _publicKey)
92
+ })
93
+ };
94
+ }
95
+ /**
96
+ * Signs the provided personal message.
97
+ * @returns The signed message bytes and signature.
98
+ */
99
+ async signPersonalMessage(bytes) {
100
+ const intentMessage = (0, import_cryptography.messageWithIntent)("PersonalMessage", bytes);
101
+ const { signature } = await __privateGet(this, _ledgerClient).signTransaction(
102
+ __privateGet(this, _derivationPath),
103
+ intentMessage
104
+ );
105
+ return {
106
+ bytes: (0, import_utils.toBase64)(bytes),
107
+ signature: (0, import_cryptography.toSerializedSignature)({
108
+ signature,
109
+ signatureScheme: this.getKeyScheme(),
110
+ publicKey: __privateGet(this, _publicKey)
111
+ })
112
+ };
113
+ }
114
+ /**
115
+ * Prepares the signer by fetching and setting the public key from a Ledger device.
116
+ * It is recommended to initialize an `LedgerSigner` instance using this function.
117
+ * @returns A promise that resolves once a `LedgerSigner` instance is prepared (public key is set).
118
+ */
119
+ static async fromDerivationPath(derivationPath, ledgerClient, suiClient) {
120
+ const { publicKey } = await ledgerClient.getPublicKey(derivationPath);
121
+ if (!publicKey) {
122
+ throw new Error("Failed to get public key from Ledger.");
123
+ }
124
+ return new _LedgerSigner({
125
+ derivationPath,
126
+ publicKey: new import_ed25519.Ed25519PublicKey(publicKey),
127
+ ledgerClient,
128
+ suiClient
129
+ });
130
+ }
131
+ /**
132
+ * Generic signing is not supported by Ledger.
133
+ * @throws Always throws an error indicating generic signing is unsupported.
134
+ */
135
+ sign() {
136
+ throw new Error("Ledger Signer does not support generic signing.");
137
+ }
138
+ /**
139
+ * Generic signing is not supported by Ledger.
140
+ * @throws Always throws an error indicating generic signing is unsupported.
141
+ */
142
+ signWithIntent() {
143
+ throw new Error("Ledger Signer does not support generic signing.");
144
+ }
145
+ };
146
+ _derivationPath = new WeakMap();
147
+ _publicKey = new WeakMap();
148
+ _ledgerClient = new WeakMap();
149
+ _suiClient = new WeakMap();
150
+ _LedgerSigner_instances = new WeakSet();
151
+ getClearSigningOptions_fn = async function(transactionBytes) {
152
+ const transaction = import_transactions.Transaction.from(transactionBytes);
153
+ const data = transaction.getData();
154
+ const gasObjectIds = data.gasData.payment?.map((object) => object.objectId) ?? [];
155
+ const inputObjectIds = data.inputs.map((input) => {
156
+ return input.$kind === "Object" && input.Object.$kind === "ImmOrOwnedObject" ? input.Object.ImmOrOwnedObject.objectId : null;
157
+ }).filter((objectId) => !!objectId);
158
+ const objects = await __privateGet(this, _suiClient).multiGetObjects({
159
+ ids: [...gasObjectIds, ...inputObjectIds],
160
+ options: {
161
+ showBcs: true,
162
+ showPreviousTransaction: true,
163
+ showStorageRebate: true,
164
+ showOwner: true
165
+ }
166
+ });
167
+ const bcsObjects = objects.map((object) => {
168
+ if (object.error || !object.data || object.data.bcs?.dataType !== "moveObject") {
169
+ return null;
170
+ }
171
+ return import_bcs.SuiMoveObject.serialize({
172
+ data: {
173
+ MoveObject: {
174
+ type: object.data.bcs.type,
175
+ hasPublicTransfer: object.data.bcs.hasPublicTransfer,
176
+ version: object.data.bcs.version,
177
+ contents: object.data.bcs.bcsBytes
178
+ }
179
+ },
180
+ owner: object.data.owner,
181
+ previousTransaction: object.data.previousTransaction,
182
+ storageRebate: object.data.storageRebate
183
+ }).toBytes();
184
+ }).filter((bcsBytes) => !!bcsBytes);
185
+ return { bcsObjects };
186
+ };
187
+ let LedgerSigner = _LedgerSigner;
188
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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 { SuiMoveObject } from './bcs.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(bytes: Uint8Array): Promise<SignatureWithBytes> {\n\t\tconst transactionOptions = await this.#getClearSigningOptions(bytes).catch(() => ({\n\t\t\t// Fail gracefully so network errors or serialization issues don't break transaction signing:\n\t\t\tbcsObjects: [],\n\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);\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('PersonalMessage', bytes);\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\tasync #getClearSigningOptions(transactionBytes: Uint8Array) {\n\t\tconst transaction = Transaction.from(transactionBytes);\n\t\tconst data = transaction.getData();\n\n\t\tconst gasObjectIds = data.gasData.payment?.map((object) => object.objectId) ?? [];\n\t\tconst inputObjectIds = data.inputs\n\t\t\t.map((input) => {\n\t\t\t\treturn input.$kind === 'Object' && input.Object.$kind === 'ImmOrOwnedObject'\n\t\t\t\t\t? input.Object.ImmOrOwnedObject.objectId\n\t\t\t\t\t: null;\n\t\t\t})\n\t\t\t.filter((objectId): objectId is string => !!objectId);\n\n\t\tconst objects = await this.#suiClient.multiGetObjects({\n\t\t\tids: [...gasObjectIds, ...inputObjectIds],\n\t\t\toptions: {\n\t\t\t\tshowBcs: true,\n\t\t\t\tshowPreviousTransaction: true,\n\t\t\t\tshowStorageRebate: true,\n\t\t\t\tshowOwner: true,\n\t\t\t},\n\t\t});\n\n\t\t// NOTE: We should probably get rid of this manual serialization logic in favor of using the\n\t\t// already serialized object bytes from the GraphQL API once there is more mainstream support\n\t\t// for it + we can enforce the transport type on the Sui client.\n\t\tconst bcsObjects = objects\n\t\t\t.map((object) => {\n\t\t\t\tif (object.error || !object.data || object.data.bcs?.dataType !== 'moveObject') {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\treturn SuiMoveObject.serialize({\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tMoveObject: {\n\t\t\t\t\t\t\ttype: object.data.bcs.type,\n\t\t\t\t\t\t\thasPublicTransfer: object.data.bcs.hasPublicTransfer,\n\t\t\t\t\t\t\tversion: object.data.bcs.version,\n\t\t\t\t\t\t\tcontents: object.data.bcs.bcsBytes,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\towner: object.data.owner!,\n\t\t\t\t\tpreviousTransaction: object.data.previousTransaction!,\n\t\t\t\t\tstorageRebate: object.data.storageRebate!,\n\t\t\t\t}).toBytes();\n\t\t\t})\n\t\t\t.filter((bcsBytes): bcsBytes is Uint8Array => !!bcsBytes);\n\n\t\treturn { bcsObjects };\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": ";;;;;;;;;;;;;;;;;;;;;;;;;;AA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AAW;AAAA,IACZ;AAAA,EACD,CAAC;AAKD,QAAM,aAAa,QACjB,IAAI,CAAC,WAAW;AAChB,QAAI,OAAO,SAAS,CAAC,OAAO,QAAQ,OAAO,KAAK,KAAK,aAAa,cAAc;AAC/E,aAAO;AAAA,IACR;AAEA,WAAO,yBAAc,UAAU;AAAA,MAC9B,MAAM;AAAA,QACL,YAAY;AAAA,UACX,MAAM,OAAO,KAAK,IAAI;AAAA,UACtB,mBAAmB,OAAO,KAAK,IAAI;AAAA,UACnC,SAAS,OAAO,KAAK,IAAI;AAAA,UACzB,UAAU,OAAO,KAAK,IAAI;AAAA,QAC3B;AAAA,MACD;AAAA,MACA,OAAO,OAAO,KAAK;AAAA,MACnB,qBAAqB,OAAO,KAAK;AAAA,MACjC,eAAe,OAAO,KAAK;AAAA,IAC5B,CAAC,EAAE,QAAQ;AAAA,EACZ,CAAC,EACA,OAAO,CAAC,aAAqC,CAAC,CAAC,QAAQ;AAEzD,SAAO,EAAE,WAAW;AACrB;AA5JM,IAAM,eAAN;",
6
+ "names": []
7
+ }
@@ -0,0 +1,27 @@
1
+ import type { ObjectOwner } from '@mysten/sui/client';
2
+ export declare const SuiMoveObject: import("@mysten/sui/bcs").BcsType<{
3
+ data: {
4
+ MoveObject: {
5
+ type: any;
6
+ hasPublicTransfer: boolean;
7
+ version: string;
8
+ contents: any;
9
+ };
10
+ $kind: "MoveObject";
11
+ };
12
+ owner: any;
13
+ previousTransaction: string;
14
+ storageRebate: string;
15
+ }, {
16
+ data: {
17
+ MoveObject: {
18
+ type: string;
19
+ hasPublicTransfer: boolean;
20
+ version: string | number | bigint;
21
+ contents: string;
22
+ };
23
+ };
24
+ owner: ObjectOwner;
25
+ previousTransaction: string;
26
+ storageRebate: string | number | bigint;
27
+ }>;
@@ -0,0 +1,70 @@
1
+ import { bcs, TypeTagSerializer } from "@mysten/sui/bcs";
2
+ import {
3
+ fromBase64,
4
+ normalizeStructTag,
5
+ normalizeSuiAddress,
6
+ parseStructTag
7
+ } from "@mysten/sui/utils";
8
+ const SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress("0x2");
9
+ const SUI_SYSTEM_ADDRESS = normalizeSuiAddress("0x3");
10
+ const MoveObjectType = bcs.enum("MoveObjectType", {
11
+ Other: bcs.StructTag,
12
+ GasCoin: null,
13
+ StakedSui: null,
14
+ Coin: bcs.TypeTag
15
+ });
16
+ const SuiMoveObject = bcs.struct("SuiMoveObject", {
17
+ data: bcs.enum("Data", {
18
+ MoveObject: bcs.struct("MoveObject", {
19
+ type: MoveObjectType.transform({
20
+ input: (objectType) => {
21
+ const structTag = parseStructTag(objectType);
22
+ if (structTag.address === SUI_FRAMEWORK_ADDRESS && structTag.module === "coin" && structTag.name === "Coin" && typeof structTag.typeParams[0] === "object") {
23
+ const innerStructTag = structTag.typeParams[0];
24
+ if (innerStructTag.address === SUI_FRAMEWORK_ADDRESS && innerStructTag.module === "sui" && innerStructTag.name === "SUI") {
25
+ return { GasCoin: true, $kind: "GasCoin" };
26
+ }
27
+ return { Coin: normalizeStructTag(innerStructTag), $kind: "Coin" };
28
+ } else if (structTag.address === SUI_SYSTEM_ADDRESS && structTag.module === "staking_pool" && structTag.name === "StakedSui") {
29
+ return { StakedSui: true, $kind: "StakedSui" };
30
+ }
31
+ return {
32
+ Other: {
33
+ ...structTag,
34
+ typeParams: structTag.typeParams.map((typeParam) => {
35
+ return TypeTagSerializer.parseFromStr(normalizeStructTag(typeParam));
36
+ })
37
+ },
38
+ $kind: "Other"
39
+ };
40
+ }
41
+ }),
42
+ hasPublicTransfer: bcs.bool(),
43
+ version: bcs.u64(),
44
+ contents: bcs.byteVector().transform({ input: fromBase64 })
45
+ })
46
+ }),
47
+ owner: bcs.Owner.transform({
48
+ input: (objectOwner) => {
49
+ if (objectOwner === "Immutable") {
50
+ return { Immutable: null };
51
+ } else if ("Shared" in objectOwner) {
52
+ return { Shared: { initialSharedVersion: objectOwner.Shared.initial_shared_version } };
53
+ } else if ("ConsensusV2" in objectOwner) {
54
+ return {
55
+ ConsensusV2: {
56
+ authenticator: objectOwner.ConsensusV2.authenticator,
57
+ startVersion: objectOwner.ConsensusV2.start_version
58
+ }
59
+ };
60
+ }
61
+ return objectOwner;
62
+ }
63
+ }),
64
+ previousTransaction: bcs.ObjectDigest,
65
+ storageRebate: bcs.u64()
66
+ });
67
+ export {
68
+ SuiMoveObject
69
+ };
70
+ //# sourceMappingURL=bcs.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/ledger/bcs.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs, TypeTagSerializer } from '@mysten/sui/bcs';\nimport type { ObjectOwner } from '@mysten/sui/client';\nimport {\n\tfromBase64,\n\tnormalizeStructTag,\n\tnormalizeSuiAddress,\n\tparseStructTag,\n} from '@mysten/sui/utils';\n\nconst SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress('0x2');\nconst SUI_SYSTEM_ADDRESS = normalizeSuiAddress('0x3');\n\nconst MoveObjectType = bcs.enum('MoveObjectType', {\n\tOther: bcs.StructTag,\n\tGasCoin: null,\n\tStakedSui: null,\n\tCoin: bcs.TypeTag,\n});\n\nexport const SuiMoveObject = bcs.struct('SuiMoveObject', {\n\tdata: bcs.enum('Data', {\n\t\tMoveObject: bcs.struct('MoveObject', {\n\t\t\ttype: MoveObjectType.transform({\n\t\t\t\tinput: (objectType: string): typeof MoveObjectType.$inferType => {\n\t\t\t\t\tconst structTag = parseStructTag(objectType);\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tstructTag.address === SUI_FRAMEWORK_ADDRESS &&\n\t\t\t\t\t\tstructTag.module === 'coin' &&\n\t\t\t\t\t\tstructTag.name === 'Coin' &&\n\t\t\t\t\t\ttypeof structTag.typeParams[0] === 'object'\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst innerStructTag = structTag.typeParams[0];\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tinnerStructTag.address === SUI_FRAMEWORK_ADDRESS &&\n\t\t\t\t\t\t\tinnerStructTag.module === 'sui' &&\n\t\t\t\t\t\t\tinnerStructTag.name === 'SUI'\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn { GasCoin: true, $kind: 'GasCoin' };\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn { Coin: normalizeStructTag(innerStructTag), $kind: 'Coin' };\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tstructTag.address === SUI_SYSTEM_ADDRESS &&\n\t\t\t\t\t\tstructTag.module === 'staking_pool' &&\n\t\t\t\t\t\tstructTag.name === 'StakedSui'\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn { StakedSui: true, $kind: 'StakedSui' };\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\tOther: {\n\t\t\t\t\t\t\t...structTag,\n\t\t\t\t\t\t\ttypeParams: structTag.typeParams.map((typeParam) => {\n\t\t\t\t\t\t\t\treturn TypeTagSerializer.parseFromStr(normalizeStructTag(typeParam));\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t},\n\t\t\t\t\t\t$kind: 'Other',\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t}),\n\t\t\thasPublicTransfer: bcs.bool(),\n\t\t\tversion: bcs.u64(),\n\t\t\tcontents: bcs.byteVector().transform({ input: fromBase64 }),\n\t\t}),\n\t}),\n\towner: bcs.Owner.transform({\n\t\tinput: (objectOwner: ObjectOwner) => {\n\t\t\tif (objectOwner === 'Immutable') {\n\t\t\t\treturn { Immutable: null };\n\t\t\t} else if ('Shared' in objectOwner) {\n\t\t\t\treturn { Shared: { initialSharedVersion: objectOwner.Shared.initial_shared_version } };\n\t\t\t} else if ('ConsensusV2' in objectOwner) {\n\t\t\t\treturn {\n\t\t\t\t\tConsensusV2: {\n\t\t\t\t\t\tauthenticator: objectOwner.ConsensusV2.authenticator,\n\t\t\t\t\t\tstartVersion: objectOwner.ConsensusV2.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