Skip to main content
Version: 10.8.0

Class: LedgerSigner231<Transport>

Defined in: src/signer/ledgerSigner231.ts:37

Signer for accounts using a Ledger Nano S+/X signature (Starknet Ledger APP version 2.3.1).

The Ledger has to be connected, unlocked and the Starknet APP has to be selected prior of use of this class.

Extends​

Type Parameters​

Transport​

Transport extends Record<any, any> = any

Implements​

Constructors​

Constructor​

new LedgerSigner231<Transport>(transport, accountID, eip2645application?, pathFunction?): LedgerSigner231<Transport>

Defined in: src/signer/ledgerSigner231.ts:63

constructor of the LedgerSigner class.

Parameters​

transport​

Transport

5 transports are available to handle USB, bluetooth, Node, Web, Mobile. See Guides for more details.

accountID​

number

ID of Ledger Nano account (can handle 2**31 accounts).

eip2645application?​

string = 'LedgerW'

A wallet is defined by an ERC2645 derivation path (6 items). One item is called application and can be customized. Default value is LedgerW.

pathFunction?​

LedgerPathCalculation = getLedgerPathBuffer221

defines the function that will calculate the path. By default getLedgerPathBuffer221 is selected.

If you are using APP v2.3.1 with an account created with the v1.1.1, you need to use :

const myLedgerSigner = new LedgerSigner231(myNodeTransport, 0, undefined, getLedgerPathBuffer111);

Returns​

LedgerSigner231<Transport>

Example​

import TransportNodeHid from '@ledgerhq/hw-transport-node-hid';
const myNodeTransport = await TransportNodeHid.create();
const myLedgerSigner = new LedgerSigner231(myNodeTransport, 0);

Overrides​

LedgerSigner221.constructor

Properties​

transporter​

readonly transporter: any

Defined in: src/signer/ledgerSigner111.ts:44

Inherited from​

LedgerSigner221.transporter


_transporter​

protected _transporter: any

Defined in: src/signer/ledgerSigner111.ts:47

Inherited from​

LedgerSigner221._transporter


accountID​

readonly accountID: number

Defined in: src/signer/ledgerSigner111.ts:49

Inherited from​

LedgerSigner221.accountID


eip2645applicationName​

readonly eip2645applicationName: string

Defined in: src/signer/ledgerSigner111.ts:51

Inherited from​

LedgerSigner221.eip2645applicationName


pathBuffer​

readonly pathBuffer: Uint8Array

Defined in: src/signer/ledgerSigner111.ts:53

Inherited from​

LedgerSigner221.pathBuffer


appVersion​

protected appVersion: string

Defined in: src/signer/ledgerSigner111.ts:55

Inherited from​

LedgerSigner221.appVersion


pubKey​

protected pubKey: string

Defined in: src/signer/ledgerSigner111.ts:57

Inherited from​

LedgerSigner221.pubKey


fullPubKey​

protected fullPubKey: string

Defined in: src/signer/ledgerSigner111.ts:59

Inherited from​

LedgerSigner221.fullPubKey

Methods​

signTxV3()​

signTxV3(txDetails, calls): Promise<{ hash: bigint; signature: Signature; }>

Defined in: src/signer/ledgerSigner231.ts:100

Ask to the Ledger Nano to display and sign a Starknet V3 transaction (Rpc 0.7 & Rpc 0.8).

Parameters​

txDetails​

V3InvocationsSignerDetails

All the details needed for a txV3.

calls​

Call[]

array of Starknet invocations

Returns​

Promise<{ hash: bigint; signature: Signature; }>

an object including the transaction Hash and the signature

Example​

const calls: Call[] = [
{
contractAddress: '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
entrypoint: 'transfer',
calldata: [
'0x11f5fc2a92ac03434a7937fe982f5e5293b65ad438a989c5b78fb8f04a12016',
'0x9184e72a000',
'0x0',
],
},
];
const txDetailsV3: V3InvocationsSignerDetails = {
chainId: constants.StarknetChainId.SN_MAIN,
nonce: '28',
accountDeploymentData: [],
paymasterData: [],
cairoVersion: '1',
feeDataAvailabilityMode: 'L1',
nonceDataAvailabilityMode: 'L1',
resourceBounds: {
l1_gas: { max_amount: '0x2a00', max_price_per_unit: '0x5c00000' },
l2_gas: { max_amount: '0x00', max_price_per_unit: '0x00' },
},
tip: 0,
version: '0x3',
walletAddress: account0.address,
}; // Rpc 0.7 transaction.
const res = await myLedgerSigner.signTxV3(txDetailsV3, calls);
// res = {hash:
// signature:
// }

Overrides​

LedgerSigner221.signTxV3


signDeployAccountV3()​

signDeployAccountV3(deployAccountDetail): Promise<{ hash: bigint; signature: Signature; }>

Defined in: src/signer/ledgerSigner231.ts:217

Ask the Ledger Nano to display and sign a Starknet V3 account deployment (Rpc 0.7 & Rpc 0.8).

Parameters​

deployAccountDetail​

V3DeployAccountSignerDetails

All the details needed for a V3 deploy account.

Returns​

Promise<{ hash: bigint; signature: Signature; }>

an object including the transaction Hash and the signature

Example​

const deployData: V3DeployAccountSignerDetails = {
tip: 0,
paymasterData: [],
accountDeploymentData: [],
nonceDataAvailabilityMode: 'L1',
feeDataAvailabilityMode: 'L1',
resourceBounds: {
l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' },
l1_gas: { max_amount: '0x226', max_price_per_unit: '0x22ecb25c00' },
},
classHash: '0x540d7f5ec7ecf317e68d48564934cb99259781b1ee3cedbbc37ec5337f8e688',
constructorCalldata: [
'3571125127744830445572285574469842579401255431821644822726857471463672199621',
],
contractAddress: '0x4ca062add1cf12a107be1107af17981cf6e544a24d987693230ea481d3d5e34',
addressSalt: '0x07e52f68e3160e1ef698211cdf6d3792368fe347e7e2d4a8ace14d9b248f39c5',
chainId: '0x534e5f5345504f4c4941',
maxFee: 0,
version: '0x3',
nonce: 0n,
}; // Rpc 0.7 transaction.
const res = await myLedgerSigner.signDeployAccountV3(deployData);
// res = {hash:
// signature:
// }

Overrides​

LedgerSigner221.signDeployAccountV3


encodeCall()​

protected encodeCall(call): Uint8Array<ArrayBufferLike>[]

Defined in: src/signer/ledgerSigner231.ts:307

Internal function to convert a Call to an array of Uint8Array.

Parameters​

call​

Call

A Call to convert.

Returns​

Uint8Array<ArrayBufferLike>[]

Call encoded in an array of Uint8Array (each containing 7 u256).

Overrides​

LedgerSigner221.encodeCall


signTransaction()​

signTransaction(transactions, transactionsDetail): Promise<Signature>

Defined in: src/signer/ledgerSigner221.ts:114

Sign in a Ledger a V1 or a V3 transaction. The details are displayed on the Ledger screen.

Parameters​

transactions​

Call[]

An array of Call transactions (generated for example by myContract.populate()).

transactionsDetail​

InvocationsSignerDetails

An object that includes all the necessary inputs to hash the transaction. Can be V2InvocationsSignerDetails or V3InvocationsSignerDetails type.

Returns​

Promise<Signature>

The signed transaction.

Example​

const txDetailsV3: V3InvocationsSignerDetails = {
chainId: constants.StarknetChainId.SN_MAIN,
nonce: '28',
accountDeploymentData: [],
paymasterData: [],
cairoVersion: '1',
feeDataAvailabilityMode: 'L1',
nonceDataAvailabilityMode: 'L1',
resourceBounds: {
l1_gas: {
max_amount: '0x2a00',
max_price_per_unit: '0x5c00000',
},
l2_gas: {
max_amount: '0x00',
max_price_per_unit: '0x00',
},
},
tip: 0,
version: '0x3',
walletAddress: account0.address,
};
const result = myLedgerSigner.signTransaction([call0, call1], txDetailsV3);
// result = Signature { r: 611475243393396148729326917410546146405234155928298353899191529090923298688n,
// s: 798839819213540985856952481651392652149797817551686626114697493101433761982n,
// recovery: 0}

Implementation of​

SignerInterface.signTransaction

Inherited from​

LedgerSigner221.signTransaction


signDeployAccountTransaction()​

signDeployAccountTransaction(details): Promise<Signature>

Defined in: src/signer/ledgerSigner221.ts:151

Sign in a Ledger the deployment of a new account. The details are displayed on the Ledger screen.

Parameters​

details​

V3DeployAccountSignerDetails

An object that includes all necessary data to calculate the Hash. It can be V2DeployAccountSignerDetails or V3DeployAccountSignerDetails types.

Returns​

Promise<Signature>

The deploy account signature.

Example​

const result = myLedgerSigner.signDeployAccountTransaction(details);
// result = Signature { r: 611475243393396148729326917410546146405234155928298353899191529090923298688n,
// s: 798839819213540985856952481651392652149797817551686626114697493101433761982n,
// recovery: 0}

Implementation of​

SignerInterface.signDeployAccountTransaction

Inherited from​

LedgerSigner221.signDeployAccountTransaction


convertBnToLedger()​

protected convertBnToLedger(input): Uint8Array

Defined in: src/signer/ledgerSigner221.ts:182

Internal function to convert a bigNumberish to an Uint8array of 256 bits

Parameters​

input​

BigNumberish

input value

Returns​

Uint8Array

a Uint8Array containing 32 bytes.

Inherited from​

LedgerSigner221.convertBnToLedger


decodeSignatureLedger()​

protected decodeSignatureLedger(respSign): object

Defined in: src/signer/ledgerSigner221.ts:191

Internal function to decode the response of the Ledger signature

Parameters​

respSign​

Uint8Array

the Buffer response of the Ledger

Returns​

object

transaction hash & signature

hash​

hash: bigint

signature​

signature: Signature

Inherited from​

LedgerSigner221.decodeSignatureLedger


getPubKey()​

getPubKey(): Promise<string>

Defined in: src/signer/ledgerSigner111.ts:106

provides the Starknet public key

Returns​

Promise<string>

an hex string : 64 characters are Point X coordinate.

Example​

const result = await myLedgerSigner.getPubKey();
// result= "0x03681417ba3e1f050dd3ccdceb8d22b5e44fa70ee7844d472c6a768bded5174e"

Implementation of​

SignerInterface.getPubKey

Inherited from​

LedgerSigner221.getPubKey


getFullPubKey()​

getFullPubKey(): Promise<string>

Defined in: src/signer/ledgerSigner111.ts:120

provides the full public key (with parity prefix)

Returns​

Promise<string>

an hex string : 2 first characters are the parity, the 64 following characters are Point X coordinate. 64 last characters are Point Y coordinate.

Example​

const result = await myLedgerSigner.getFullPubKey();
// result= "0x0403681417ba3e1f050dd3ccdceb8d22b5e44fa70ee7844d472c6a768bded5174e03cbc86f805dcfcb0c1922dd4daf181afa289d86223a18bc856276615bcc7787"

Inherited from​

LedgerSigner221.getFullPubKey


getAppVersion()​

getAppVersion(): Promise<string>

Defined in: src/signer/ledgerSigner111.ts:134

Returns the version of the Starknet APP implemented in the Ledger.

Returns​

Promise<string>

version.

Example​

const result = await myLedgerSigner.getAppVersion();
// result= "1.1.1"

Inherited from​

LedgerSigner221.getAppVersion


signMessage()​

signMessage(typedDataToHash, accountAddress): Promise<Signature>

Defined in: src/signer/ledgerSigner111.ts:155

Sign a TypedData message (SNIP-12) in a Ledger.

Parameters​

typedDataToHash​

TypedData

A TypedData message compatible with SNIP-12.

accountAddress​

string

Signer account address (Hex or num string)

Returns​

Promise<Signature>

The signed message.

Example​

const result = myLedgerSigner.signMessage(snip12Message, account0.address);
// result = Signature { r: 611475243393396148729326917410546146405234155928298353899191529090923298688n,
// s: 798839819213540985856952481651392652149797817551686626114697493101433761982n,
// recovery: 0}

Implementation of​

SignerInterface.signMessage

Inherited from​

LedgerSigner221.signMessage


signDeclareTransaction()​

signDeclareTransaction(details): Promise<Signature>

Defined in: src/signer/ledgerSigner111.ts:267

Sign in a Ledger the declaration of a new class. This is a blind sign on the Ledger screen.

Parameters​

details​

DeclareSignerDetails

An object that includes all necessary data to calculate the Hash. It can be V3DeclareSignerDetails or V2DeclareSignerDetails types.

Returns​

Promise<Signature>

The declare Signature.

Example​

const result = myLedgerSigner.signDeclareTransaction(details);
// result = Signature { r: 611475243393396148729326917410546146405234155928298353899191529090923298688n,
// s: 798839819213540985856952481651392652149797817551686626114697493101433761982n,
// recovery: 0}

Implementation of​

SignerInterface.signDeclareTransaction

Inherited from​

LedgerSigner221.signDeclareTransaction


signRaw()​

protected signRaw(msgHash): Promise<Signature>

Defined in: src/signer/ledgerSigner111.ts:290

Internal function to sign a hash in a Ledger Nano. This is a blind sign in the Ledger ; no display of what you are signing.

Parameters​

msgHash​

string

Returns​

Promise<Signature>

Inherited from​

LedgerSigner221.signRaw


getPublicKeys()​

protected getPublicKeys(): Promise<void>

Defined in: src/signer/ledgerSigner111.ts:309

internal function to get both the Starknet public key and the full public key

Returns​

Promise<void>

Inherited from​

LedgerSigner221.getPublicKeys