Skip to main content
Version: Next

Class: LedgerSigner231<Transport>

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.

Type parameters

NameType
Transportextends Record<any, any> = any

Hierarchy

Implements

Constructors

constructor

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

constructor of the LedgerSigner class.

Type parameters

NameType
Transportextends Record<any, any> = any

Parameters

NameTypeDefault valueDescription
transportTransportundefined5 transports are available to handle USB, bluetooth, Node, Web, Mobile. See Guides for more details.
accountIDnumberundefinedID 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?LedgerPathCalculationgetLedgerPathBuffer221defines 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 : typescript 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

Defined in

src/signer/ledgerSigner231.ts:62

Properties

transporter

Readonly transporter: any

Inherited from

LedgerSigner221.transporter

Defined in

src/signer/ledgerSigner111.ts:43


_transporter

Protected _transporter: any

Inherited from

LedgerSigner221._transporter

Defined in

src/signer/ledgerSigner111.ts:46


accountID

Readonly accountID: number

Inherited from

LedgerSigner221.accountID

Defined in

src/signer/ledgerSigner111.ts:48


eip2645applicationName

Readonly eip2645applicationName: string

Inherited from

LedgerSigner221.eip2645applicationName

Defined in

src/signer/ledgerSigner111.ts:50


pathBuffer

Readonly pathBuffer: Uint8Array

Inherited from

LedgerSigner221.pathBuffer

Defined in

src/signer/ledgerSigner111.ts:52


appVersion

Protected appVersion: string

Inherited from

LedgerSigner221.appVersion

Defined in

src/signer/ledgerSigner111.ts:54


pubKey

Protected pubKey: string

Inherited from

LedgerSigner221.pubKey

Defined in

src/signer/ledgerSigner111.ts:56


fullPubKey

Protected fullPubKey: string

Inherited from

LedgerSigner221.fullPubKey

Defined in

src/signer/ledgerSigner111.ts:58

Methods

signTxV3

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

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

Parameters

NameTypeDescription
txDetailsV3InvocationsSignerDetailsAll the details needed for a txV3.
callsCall[]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

Defined in

src/signer/ledgerSigner231.ts:99


signDeployAccountV3

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

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

Parameters

NameTypeDescription
deployAccountDetailV3DeployAccountSignerDetailsAll 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

Defined in

src/signer/ledgerSigner231.ts:216


encodeCall

encodeCall(call): Uint8Array[]

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

Parameters

NameTypeDescription
callCallA Call to convert.

Returns

Uint8Array[]

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

Overrides

LedgerSigner221.encodeCall

Defined in

src/signer/ledgerSigner231.ts:306


signTransaction

signTransaction(transactions, transactionsDetail): Promise<Signature>

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

Parameters

NameTypeDescription
transactionsCall[]An array of Call transactions (generated for example by myContract.populate()).
transactionsDetailInvocationsSignerDetailsAn 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

Defined in

src/signer/ledgerSigner221.ts:113


signDeployAccountTransaction

signDeployAccountTransaction(details): Promise<Signature>

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

Parameters

NameTypeDescription
detailsV3DeployAccountSignerDetailsAn 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

Defined in

src/signer/ledgerSigner221.ts:150


convertBnToLedger

convertBnToLedger(input): Uint8Array

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

Parameters

NameTypeDescription
inputBigNumberishinput value

Returns

Uint8Array

a Uint8Array containing 32 bytes.

Inherited from

LedgerSigner221.convertBnToLedger

Defined in

src/signer/ledgerSigner221.ts:181


decodeSignatureLedger

decodeSignatureLedger(respSign): Object

Internal function to decode the response of the Ledger signature

Parameters

NameTypeDescription
respSignUint8Arraythe Buffer response of the Ledger

Returns

Object

transaction hash & signature

NameType
hashbigint
signatureSignature

Inherited from

LedgerSigner221.decodeSignatureLedger

Defined in

src/signer/ledgerSigner221.ts:190


getPubKey

getPubKey(): Promise<string>

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

Defined in

src/signer/ledgerSigner111.ts:105


getFullPubKey

getFullPubKey(): Promise<string>

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

Defined in

src/signer/ledgerSigner111.ts:119


getAppVersion

getAppVersion(): Promise<string>

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

Defined in

src/signer/ledgerSigner111.ts:133


signMessage

signMessage(typedDataToHash, accountAddress): Promise<Signature>

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

Parameters

NameTypeDescription
typedDataToHashTypedDataA TypedData message compatible with SNIP-12.
accountAddressstringSigner 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

Defined in

src/signer/ledgerSigner111.ts:154


signDeclareTransaction

signDeclareTransaction(details): Promise<Signature>

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

Parameters

NameTypeDescription
detailsDeclareSignerDetailsAn 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

Defined in

src/signer/ledgerSigner111.ts:266


signRaw

signRaw(msgHash): Promise<Signature>

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

NameType
msgHashstring

Returns

Promise<Signature>

Inherited from

LedgerSigner221.signRaw

Defined in

src/signer/ledgerSigner111.ts:289


getPublicKeys

getPublicKeys(): Promise<void>

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

Returns

Promise<void>

Inherited from

LedgerSigner221.getPublicKeys

Defined in

src/signer/ledgerSigner111.ts:308