Class: LedgerSigner221<Transport>
Defined in: src/signer/ledgerSigner221.ts:44
Signer for accounts using a Ledger Nano S+/X signature (Starknet Ledger APP version 2.2.1).
The Ledger has to be connected, unlocked and the Starknet APP has to be selected prior of use of this class.
Extends
Extended by
Type Parameters
Transport
Transport extends Record<any, any> = any
Implements
Constructors
Constructor
new LedgerSigner221<
Transport>(transport,accountID,eip2645application?,pathFunction?):LedgerSigner221<Transport>
Defined in: src/signer/ledgerSigner221.ts:70
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 (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.2.1 with an account created with the v1.1.1, you need to use :
const myLedgerSigner = new LedgerSigner211(myNodeTransport, 0, undefined, getLedgerPathBuffer111);
Returns
LedgerSigner221<Transport>
Example
import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
const myNodeTransport = await TransportNodeHid.create();
const myLedgerSigner = new LedgerSigner211(myNodeTransport, 0);
Overrides
Properties
transporter
readonlytransporter:any
Defined in: src/signer/ledgerSigner111.ts:44
Inherited from
_transporter
protected_transporter:any
Defined in: src/signer/ledgerSigner111.ts:47
Inherited from
accountID
readonlyaccountID:number
Defined in: src/signer/ledgerSigner111.ts:49
Inherited from
eip2645applicationName
readonlyeip2645applicationName:string
Defined in: src/signer/ledgerSigner111.ts:51
Inherited from
LedgerSigner111.eip2645applicationName
pathBuffer
readonlypathBuffer:Uint8Array
Defined in: src/signer/ledgerSigner111.ts:53
Inherited from
appVersion
protectedappVersion:string
Defined in: src/signer/ledgerSigner111.ts:55
Inherited from
pubKey
protectedpubKey:string
Defined in: src/signer/ledgerSigner111.ts:57
Inherited from
fullPubKey
protectedfullPubKey:string
Defined in: src/signer/ledgerSigner111.ts:59
Inherited from
Methods
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
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
Overrides
LedgerSigner111.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
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
Overrides
LedgerSigner111.signDeployAccountTransaction
convertBnToLedger()
protectedconvertBnToLedger(input):Uint8Array
Defined in: src/signer/ledgerSigner221.ts:182
Internal function to convert a bigNumberish to an Uint8array of 256 bits
Parameters
input
input value
Returns
Uint8Array
a Uint8Array containing 32 bytes.
decodeSignatureLedger()
protecteddecodeSignatureLedger(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
encodeCall()
protectedencodeCall(call):Uint8Array<ArrayBufferLike>[]
Defined in: src/signer/ledgerSigner221.ts:205
Internal function to convert a Call to an array of Uint8Array.
Parameters
call
A Call to convert.
Returns
Uint8Array<ArrayBufferLike>[]
Call encoded in an array of Uint8Array (each containing 7 u256).
signTxV3()
signTxV3(
txDetails,calls):Promise<{hash:bigint;signature:Signature; }>
Defined in: src/signer/ledgerSigner221.ts:256
Ask to the Ledger Nano to display and sign a Starknet V3 transaction.
Parameters
txDetails
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
};
const res = await myLedgerSigner.signTxV3(txDetailsV3, calls);
// res = {hash:
// signature:
// }
signDeployAccountV3()
signDeployAccountV3(
deployAccountDetail):Promise<{hash:bigint;signature:Signature; }>
Defined in: src/signer/ledgerSigner221.ts:362
Ask the Ledger Nano to display and sign a Starknet V3 account deployment.
Parameters
deployAccountDetail
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
}
const res = await myLedgerSigner.signDeployAccountV3(deployData);
// res = {hash:
// signature:
// }
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
Inherited from
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
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
signMessage()
signMessage(
typedDataToHash,accountAddress):Promise<Signature>
Defined in: src/signer/ledgerSigner111.ts:155
Sign a TypedData message (SNIP-12) in a Ledger.
Parameters
typedDataToHash
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
Inherited from
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
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
LedgerSigner111.signDeclareTransaction
signRaw()
protectedsignRaw(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
getPublicKeys()
protectedgetPublicKeys():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>