Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Haynes committed Aug 15, 2024
1 parent 7d62567 commit be989a4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
42 changes: 24 additions & 18 deletions packages/cookbook/accounts/access-keys/create-full-access-key.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
const { KeyPair, keyStores, connect } = require("near-api-js");
const path = require("path");
const homedir = require("os").homedir();
const { getTestnetRpcProvider, addFullAccessKey, getSignerFromKeystore } = require('@near-js/client');
const { KeyPair } = require('@near-js/crypto');
const path = require('path');
const homedir = require('os').homedir();

const CREDENTIALS_DIR = ".near-credentials";
const ACCOUNT_ID = "example.testnet";
const CREDENTIALS_DIR = '.near-credentials';
const ACCOUNT_ID = 'example.testnet';
const credentialsPath = path.join(homedir, CREDENTIALS_DIR);
const keyStore = new keyStores.UnencryptedFileSystemKeyStore(credentialsPath);

const config = {
keyStore,
networkId: "testnet",
nodeUrl: "https://rpc.testnet.near.org",
};
// const config = {
// keyStore,
// networkId: 'testnet',
// nodeUrl: 'https://rpc.testnet.near.org',
// };
//
// createFullAccessKey(ACCOUNT_ID);

createFullAccessKey(ACCOUNT_ID);
async function createFullAccessKeyExample(accountId) {
const keyPair = KeyPair.fromRandom('ed25519');
await addFullAccessKey({
account: ACCOUNT_ID,
publicKey: keyPair.getPublicKey(),
deps: {
rpcProvider: getTestnetRpcProvider(),
signer: getSignerFromKeystore(keyStore),
},
});

async function createFullAccessKey(accountId) {
const keyPair = KeyPair.fromRandom("ed25519");
const publicKey = keyPair.publicKey.toString();
const near = await connect(config);
const account = await near.account(accountId);
await keyStore.setKey(config.networkId, publicKey, keyPair);
await account.addKey(publicKey);
await keyStore.setKey('testnet', accountId, keyPair);
}
2 changes: 2 additions & 0 deletions packages/cookbook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"license": "ISC",
"dependencies": {
"@near-js/accounts": "workspace:*",
"@near-js/client": "workspace:*",
"@near-js/crypto": "workspace:*",
"@near-js/keystores-node": "workspace:*",
"@near-js/providers": "workspace:*",
"@near-js/signers": "workspace:*",
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit be989a4

Please sign in to comment.