-
Notifications
You must be signed in to change notification settings - Fork 4
/
v4convert_bip39_seed_to_dydxv4seed.js
49 lines (45 loc) · 1.35 KB
/
v4convert_bip39_seed_to_dydxv4seed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const { deriveHDKeyFromEthereumSignature } = require('@dydxprotocol/v4-client-js/build/src/lib/onboarding.js');
const { BECH32_PREFIX } = require('@dydxprotocol/v4-client-js/build/src');
const LocalWallet = require('@dydxprotocol/v4-client-js/build/src/clients/modules/local-wallet').default;
const { ethers } = require('ethers');
const fs = require('fs');
// ########################## YOU FILL THIS OUT #################
const mnemonic = '<FILL_THIS_OUT>'
// ##############################################################
const wallet = ethers.Wallet.fromPhrase(mnemonic);
const toSign = {
"domain": {
"name": "dYdX V4",
"chainId": 5
},
"primaryType": "dYdX",
"types": {
"EIP712Domain": [
{
"name": "name",
"type": "string"
},
{
"name": "chainId",
"type": "uint256"
}
],
"dYdX": [
{
"name": "action",
"type": "string"
}
]
},
"message": {
"action": "dYdX Chain Onboarding"
}
};
(async () => {
const signature = await wallet.signTypedData(toSign.domain, { dYdX: toSign.types.dYdX }, toSign.message);
console.log('Signed Data:', signature);
const k = deriveHDKeyFromEthereumSignature(signature);
console.log('Mnemonic:', k.mnemonic);
const lw = await LocalWallet.fromMnemonic(k.mnemonic, BECH32_PREFIX);
console.log('Address:', lw.address)
})();