-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New translations keystorev4-multi.mdx (Chinese Traditional)
- Loading branch information
Showing
1 changed file
with
199 additions
and
0 deletions.
There are no files selected for viewing
199 changes: 199 additions & 0 deletions
199
...t/references/sdk/ethers-ext/v5/account-management/keystore/keystoreV4-multi.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
# V4 keystore multi | ||
|
||
本例演示如何加密和解密 **keystore V4 multi**。 | ||
|
||
<CH.Spotlight> | ||
<CH.Code> | ||
```js keystoreV4-multi.js | ||
const { | ||
Wallet | ||
} = require("@kaiachain/ethers-ext/v5"); | ||
|
||
// Klaytn V4 with multiple role-based keys. https://toolkit.klaytn.foundation/misc/generateKeystore | ||
const encryptedKey = `{ | ||
"version": 4, | ||
"id":"2d7ad5c1-880f-4920-9b8e-51f852c4802c", | ||
"address":"0x17226c9b4e130551c258eb7b1cdc927c13998cd6", | ||
"keyring":[ | ||
[ | ||
{ | ||
"ciphertext":"eb9bd884ac3cc8bf92e6b0082e9d07198bfc4c1223ccc6e5edf7452ad612b2b5", | ||
"cipherparams":{"iv":"47faf7b0991a051eef698c73fc246f78"}, | ||
"cipher":"aes-128-ctr", | ||
"kdf":"scrypt", | ||
"kdfparams":{"dklen":32,"salt":"ba0a3e8dc49a04f8e590f8df5a590bc6e134b031ce10f46d73d4c459aa4c08f8","n":4096,"r":8,"p":1}, | ||
"mac":"4978d7325e1b9b3ec9fdfd1ec709a5a86fdfade0297ea9ddeeb8c3a7a62ae898" | ||
} | ||
], | ||
[ | ||
{ | ||
"ciphertext":"1a80c8666bea1a8dfa3082b001ff64c818fb14cf4e02017785e0edcc7a277af4", | ||
"cipherparams":{"iv":"eafbecc65ccc177a5579bf56d5f4ed31"}, | ||
"cipher":"aes-128-ctr", | ||
"kdf":"scrypt", | ||
"kdfparams":{"dklen":32,"salt":"6472845219e11e4de094cac8c32a6a4d13e69cd4507780a7a37f5e411e1d895d","n":4096,"r":8,"p":1}, | ||
"mac":"86379236d2fd6e9bb3f99f7eebaa3325b51e9fa5ec150ade7a461555c0a14ca3" | ||
}, | ||
{ | ||
"ciphertext":"0071c41d2956b12be5ebc08a9a5b3a9684b9e410fe2de91d614be977fb2a0bdb", | ||
"cipherparams":{"iv":"1492dfb771030d3d9c9d996c193c03e5"}, | ||
"cipher":"aes-128-ctr", | ||
"kdf":"scrypt", | ||
"kdfparams":{"dklen":32,"salt":"f8145aa907a649866e0fbff86011244584ddc86559cf4901f8f69b670c234fd7","n":4096,"r":8,"p":1}, | ||
"mac":"eacc58c1ad717ca375697c9fcc80f463a26600f5da1b21327715bf3efa047be5" | ||
} | ||
], | ||
[ | ||
{ | ||
"ciphertext":"68ffc1e2800a7288ba7baba0f0f8049daeed05379fabfdd3bc017fa85c49ab50", | ||
"cipherparams":{"iv":"17f22d7b8aa1a8a2948fd3629f0b89ed"}, | ||
"cipher":"aes-128-ctr", | ||
"kdf":"scrypt", | ||
"kdfparams":{"dklen":32,"salt":"ff5e577ec8294320cfe59ef7b1b01ee44d4c9f19c8fbc31f333059c74eb8c6d2","n":4096,"r":8,"p":1}, | ||
"mac":"de65d669be044df5e39e678b099424a8692a2da6f3746832862cf2e5d6ada612" | ||
}, | ||
{ | ||
"ciphertext":"fd4810ee850f0aa5f61a2eafbfc5ca36cfebb42df5c2465cc8ae5188029b188b", | ||
"cipherparams":{"iv":"b00ead13b38e449c268d09fced80ce49"}, | ||
"cipher":"aes-128-ctr", | ||
"kdf":"scrypt", | ||
"kdfparams":{"dklen":32,"salt":"af5dbbfb7383045dc7f8a3bfc56cccfc22a5150a1f87e454d40893a4b6fea9a1","n":4096,"r":8,"p":1}, | ||
"mac":"6234352852eb18246b94f28f3c3454103289ecf2faaa91115927c53729bb0805" | ||
}, | ||
{ | ||
"ciphertext":"03b758de6372aa6bedde513ccb282bf8af32bca227c258f3e0fc85ce454d72a4", | ||
"cipherparams":{"iv":"5c20f3e96d0802eaf56670e57fbe3e98"}, | ||
"cipher":"aes-128-ctr", | ||
"kdf":"scrypt", | ||
"kdfparams":{"dklen":32,"salt":"b5ec4e40f5a09a59e90317ce45eb7bcd73a2a9afe70f6f2e32548fd38ed2da3b","n":4096,"r":8,"p":1}, | ||
"mac":"99b7f59855f0aa04531cc4a24c7923f75ed8052084de9ec49a2794e3899c3274" | ||
} | ||
] | ||
] | ||
}`; | ||
const password = "password"; | ||
const newPassword = "newPassword"; | ||
|
||
// Be sure that decrypted Keystore v4 object is not supported to encrypt keystore v4 again. | ||
// so this example shows only decrypting Keystore v4 and encrypting it as keysotre v3. | ||
// Be sure that klaytn address is lost when each account of keystore v4 is encrypted as keysotre v3, | ||
// because keystore v3 does not support klaytn account system. | ||
async function main() { | ||
const accounts = Wallet.fromEncryptedJsonListSync(encryptedKey, password); | ||
|
||
console.log("decrypted (address, privateKey)"); | ||
for (const account of accounts) { | ||
console.log(account.klaytnAddr, ", ", account.privateKey); | ||
} | ||
|
||
console.log("\ndecrypted (address, privateKey) with new password"); | ||
for (const account of accounts) { | ||
const v3encryptedKey = await account.encrypt(newPassword); | ||
const newAccount = Wallet.fromEncryptedJsonSync(v3encryptedKey, newPassword); | ||
|
||
console.log(newAccount.address, ", ", newAccount.privateKey); | ||
} | ||
} | ||
|
||
main(); | ||
``` | ||
|
||
--- | ||
|
||
```zsh output | ||
❯ node keystoreV4-multi.js | ||
decrypted (address, privateKey) | ||
0x17226c9b4e130551c258eb7b1cdc927c13998cd6 , 0x278c3d035328daf04ab2597da96dd2d8868fd61a8837030f7d8a85f27b7f1bad | ||
0x17226c9b4e130551c258eb7b1cdc927c13998cd6 , 0xa06d13800719307ea7e2503ea441c2ea49279d0d600a2eec2887b50928869676 | ||
0x17226c9b4e130551c258eb7b1cdc927c13998cd6 , 0xc32f4007ffad303db99dee0d79a720e1d70c4b2babf8e33cb28170a16bac467d | ||
0x17226c9b4e130551c258eb7b1cdc927c13998cd6 , 0xc274d13302891d0d91a60891a48fde8c2860018f8dcb6293dcc0b28a238590b0 | ||
0x17226c9b4e130551c258eb7b1cdc927c13998cd6 , 0x83c127e5207b70086a702c93f1c9a041f15ce49ee5183ce848f35c64de196eff | ||
0x17226c9b4e130551c258eb7b1cdc927c13998cd6 , 0x48f97204ac4886dfbd819ada04ea31a730c6fc43fcb08900566360ee7402f93b | ||
|
||
decrypted (address, privateKey) with new password | ||
0x0cc57a3c4E276A37AB0A98ba6899CAf6037996fB , 0x278c3d035328daf04ab2597da96dd2d8868fd61a8837030f7d8a85f27b7f1bad | ||
0x1F2f81B67d1A718c09221eBeb3F12a7192389663 , 0xa06d13800719307ea7e2503ea441c2ea49279d0d600a2eec2887b50928869676 | ||
0xF5D27139C99621859e8D1b0f6Be8BF3b8dAca609 , 0xc32f4007ffad303db99dee0d79a720e1d70c4b2babf8e33cb28170a16bac467d | ||
0x7E39a9097C975E6A63f1e0ade4b7312cF2854F9c , 0xc274d13302891d0d91a60891a48fde8c2860018f8dcb6293dcc0b28a238590b0 | ||
0x09859661f2574E80C5a51EA3e0E29cA19D21f513 , 0x83c127e5207b70086a702c93f1c9a041f15ce49ee5183ce848f35c64de196eff | ||
0x3AcFe8529FD4C2028f8A26805F9Bf9bAB2cc41eF , 0x48f97204ac4886dfbd819ada04ea31a730c6fc43fcb08900566360ee7402f93b | ||
``` | ||
</CH.Code> | ||
|
||
--- | ||
|
||
從 **@kaiachain/ethers-ext/v5** 軟件包中導入錢包類。 | ||
|
||
```js keystoreV4-multi.js focus=1:3 | ||
``` | ||
|
||
--- | ||
|
||
定義加密多密鑰存儲版本 4 | ||
|
||
```js keystoreV4-multi.js focus=6:66 | ||
``` | ||
|
||
--- | ||
|
||
指定密鑰存儲的當前**密碼**和**新密碼**。 | ||
|
||
```js keystoreV4-multi.js focus=67:68 | ||
``` | ||
|
||
--- | ||
|
||
**使用**當前密碼**解密**密鑰庫 | ||
|
||
```js keystoreV4-multi.js focus=77:80 | ||
``` | ||
|
||
--- | ||
|
||
解密後,您可以訪問**公鑰**和**私鑰**。 | ||
|
||
<CH.Code> | ||
```js keystoreV4-multi.js focus=79 | ||
``` | ||
|
||
--- | ||
|
||
```zsh output | ||
decrypted (address, privateKey) | ||
0x17226c9b4e130551c258eb7b1cdc927c13998cd6 , 0x278c3d035328daf04ab2597da96dd2d8868fd61a8837030f7d8a85f27b7f1bad | ||
0x17226c9b4e130551c258eb7b1cdc927c13998cd6 , 0xa06d13800719307ea7e2503ea441c2ea49279d0d600a2eec2887b50928869676 | ||
0x17226c9b4e130551c258eb7b1cdc927c13998cd6 , 0xc32f4007ffad303db99dee0d79a720e1d70c4b2babf8e33cb28170a16bac467d | ||
0x17226c9b4e130551c258eb7b1cdc927c13998cd6 , 0xc274d13302891d0d91a60891a48fde8c2860018f8dcb6293dcc0b28a238590b0 | ||
0x17226c9b4e130551c258eb7b1cdc927c13998cd6 , 0x83c127e5207b70086a702c93f1c9a041f15ce49ee5183ce848f35c64de196eff | ||
0x17226c9b4e130551c258eb7b1cdc927c13998cd6 , 0x48f97204ac4886dfbd819ada04ea31a730c6fc43fcb08900566360ee7402f93b | ||
``` | ||
</CH.Code> | ||
|
||
--- | ||
|
||
您可以使用**加密密鑰**和**新密碼**生成**新密鑰存儲**。 請注意,新的加密密鑰將是 keystore v3。 | ||
|
||
```js keystoreV4-multi.js focus=70:73,82:88 | ||
``` | ||
|
||
--- | ||
|
||
檢查新的密鑰庫 **public** 和 **private** 密鑰,它將與原始密鑰庫不同,因為密鑰庫 v3 \*\* 不支持 klaytn 賬戶系統。 | ||
|
||
<CH.Code> | ||
```js keystoreV4-multi.js focus=85:87 | ||
``` | ||
|
||
--- | ||
|
||
```zsh output | ||
decrypted (address, privateKey) with new password | ||
0x0cc57a3c4E276A37AB0A98ba6899CAf6037996fB , 0x278c3d035328daf04ab2597da96dd2d8868fd61a8837030f7d8a85f27b7f1bad | ||
0x1F2f81B67d1A718c09221eBeb3F12a7192389663 , 0xa06d13800719307ea7e2503ea441c2ea49279d0d600a2eec2887b50928869676 | ||
0xF5D27139C99621859e8D1b0f6Be8BF3b8dAca609 , 0xc32f4007ffad303db99dee0d79a720e1d70c4b2babf8e33cb28170a16bac467d | ||
0x7E39a9097C975E6A63f1e0ade4b7312cF2854F9c , 0xc274d13302891d0d91a60891a48fde8c2860018f8dcb6293dcc0b28a238590b0 | ||
0x09859661f2574E80C5a51EA3e0E29cA19D21f513 , 0x83c127e5207b70086a702c93f1c9a041f15ce49ee5183ce848f35c64de196eff | ||
0x3AcFe8529FD4C2028f8A26805F9Bf9bAB2cc41eF , 0x48f97204ac4886dfbd819ada04ea31a730c6fc43fcb08900566360ee7402f93b | ||
``` | ||
</CH.Code> | ||
</CH.Spotlight> |