Last active
March 12, 2022 22:28
-
-
Save mattlockyer/a1798437430c16da6c016ce38f7ce762 to your computer and use it in GitHub Desktop.
near-cli and near-api-js - key rotation steps for accounts
This file contains hidden or 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
// go to https://near.github.io/seed-recovery/ and click the random button at the bottom | |
// copy publicKey AND seed phrase somewhere SAFE | |
// use the same tool to find the public key of an existing seed phrase OR call | |
near keys [accountId] | |
// once you have both public keys AND the new seed phrase SAFELY STORED | |
near add-key [accountId] [newPublicKey] | |
near delete-key [accountId] [oldPublicKey] | |
// Reference: https://www.npmjs.com/package/near-cli#near-add-key | |
// Using JS | |
const result = await account.addKey([newPublicKey]) | |
// CHECK RESULT IS SUCCESSFUL BEFORE DELETING OLD KEY!!! | |
const keys = await account.getAccessKeys() | |
// some loop, is my newPublicKey there??? | |
account.deleteKey([oldPublicKey]) | |
// Using JS 1 TX safer because will fail and do nothing or success and rotate keys | |
// import actions here nearAPI.transactions[actionName] | |
const actions = [ | |
addKey([newPublicKey]), | |
deleteKey([oldPublicKey]), | |
] | |
account.signAndSendTransaction({ | |
receiverId: account.accountId, | |
actions, | |
}) | |
// note: if the keys are the same publicKey, you will need to delete before you add, so the single TX method is the safest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment