Skip to content

Commit

Permalink
feat: bring back cli command get_app_keys
Browse files Browse the repository at this point in the history
  • Loading branch information
friedger committed Aug 17, 2021
1 parent c575ee9 commit f7d2c6c
Show file tree
Hide file tree
Showing 19 changed files with 2,034 additions and 25,123 deletions.
24,557 changes: 1,970 additions & 22,587 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/bns/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"dependencies": {
"@stacks/common": "^2.0.1",
"@stacks/network": "^1.2.2",
"@stacks/network": "^2.0.1",
"@stacks/transactions": "^2.0.1",
"@types/bn.js": "^4.11.6",
"bn.js": "^4.12.0"
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@
"typescript": "^4.2.4"
},
"dependencies": {
"@stacks/auth": "^1.2.3",
"@stacks/auth": "^2.0.1",
"@stacks/blockchain-api-client": "^0.34.1",
"@stacks/common": "^2.0.1",
"@stacks/network": "^1.2.2",
"@stacks/network": "^2.0.1",
"@stacks/stacking": "^2.0.1",
"@stacks/storage": "^2.0.1",
"@stacks/transactions": "^2.0.1",
"@stacks/wallet-sdk": "^2.0.1",
"ajv": "^4.11.5",
"bip32": "^2.0.4",
"bip39": "^3.0.2",
Expand All @@ -111,7 +112,7 @@
"node-fetch": "^2.6.0",
"ripemd160": "^2.0.1",
"winston": "^3.2.1",
"zone-file": "^1.0.0"
"zone-file": "^2.0.0-beta.3"
},
"gitHead": "77b4d6d531b74996e4b7a0cbd1cf5b8358a690ce"
}
24 changes: 5 additions & 19 deletions packages/cli/src/argparse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1240,10 +1240,10 @@ export const CLI_ARGS = {
realtype: '12_words_or_ciphertext',
},
{
name: 'name_or_id_address',
name: 'index',
type: 'string',
realtype: 'name-or-id-address',
pattern: `${NAME_PATTERN}|${SUBDOMAIN_PATTERN}|${ID_ADDRESS_PATTERN}`,
realtype: 'integer',
pattern: '^[0-9]+$',
},
{
name: 'app_origin',
Expand All @@ -1255,33 +1255,19 @@ export const CLI_ARGS = {
minItems: 3,
maxItems: 3,
help:
'Get the application private key from a 12-word backup phrase and a name or ID-address. ' +
'Get the application private key from a 12- or 24-word Secret Key and an index of the enumerated associated accounts. ' +
'This is the private key used to sign data in Gaia, and its address is the Gaia bucket ' +
'address. If you provide your encrypted backup phrase, you will be asked to decrypt it. ' +
'If you provide a name instead of an ID-address, its ID-address will be queried automatically ' +
'(note that this means that the name must already be registered).\n' +
'\n' +
'NOTE: This command does NOT verify whether or not the name or ID-address was created by the ' +
'backup phrase. You should do this yourself via the `get_owner_keys` command if you are not sure.\n' +
'\n' +
'There are two derivation paths emitted by this command: a `keyInfo` path and a `legacyKeyInfo`' +
"path. You should use the one that matches the Gaia hub read URL's address, if you have already " +
'signed in before. If not, then you should use the `keyInfo` path when possible.\n' +
'\n' +
'Example:\n' +
'\n' +
' $ export BACKUP_PHRASE="one race buffalo dynamic icon drip width lake extra forest fee kit"\n' +
' $ stx get_app_keys "$BACKUP_PHRASE" example.id.blockstack https://my.cool.dapp\n' +
' $ stx get_app_keys "$BACKUP_PHRASE" 1 https://my.cool.dapp\n' +
' {\n' +
' "keyInfo": {\n' +
' "privateKey": "TODO",\n' +
' "address": "TODO"\n' +
' },\n' +
' "legacyKeyInfo": {\n' +
' "privateKey": "90f9ec4e13fb9a00243b4c1510075157229bda73076c7c721208c2edca28ea8b",\n' +
' "address": "1Lr8ggSgdmfcb4764woYutUfFqQMjEoKHc"\n' +
' },\n' +
' "ownerKeyIndex": 0\n' +
' }',
group: 'Key Management',
},
Expand Down
27 changes: 19 additions & 8 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ import {
getpass,
getBackupPhrase,
mkdirs,
getIDAddress,
IDAppKeys,
getIDAppKeys,
makePromptsFromArgList,
Expand All @@ -112,6 +111,7 @@ import {
} from './utils';

import { handleAuth, handleSignIn } from './auth';
import { generateNewAccount, generateWallet, getAppPrivateKey } from '@stacks/wallet-sdk';

// global CLI options
let txOnly = false;
Expand Down Expand Up @@ -263,19 +263,30 @@ function profileStore(network: CLINetworkAdapter, args: string[]): Promise<strin
}

/*
* Get the app private key(s) from a backup phrase and an ID-address
* Get the app private key(s) from a backup phrase
* and an index of the enumerated accounts
* args:
* @mnemonic (string) the 12-word phrase
* @nameOrIDAddress (string) the name or ID-address
* @index (number) the index of the account
* @appOrigin (string) the application's origin URL
*/
async function getAppKeys(network: CLINetworkAdapter, args: string[]): Promise<string> {
const mnemonic = await getBackupPhrase(args[0]);
const nameOrIDAddress = args[1];
const origin = args[2];
const idAddress = await getIDAddress(network, nameOrIDAddress);
const networkInfo = await getApplicationKeyInfo(network, mnemonic, idAddress, origin);
return JSONStringify(networkInfo);
const index = parseInt(args[1]);
if (index <= 0) throw new Error('index must be greater than 0');
const appDomain = args[2];
let wallet = await generateWallet({ secretKey: mnemonic, password: '' });
for (let i = 0; i < index; i++) {
wallet = generateNewAccount(wallet);
}
const account = wallet.accounts[index - 1];
const privateKey = getAppPrivateKey({ account, appDomain });
const address = getAddressFromPrivateKey(
privateKey,
network.isMainnet() ? TransactionVersion.Mainnet : TransactionVersion.Testnet
);

return JSON.stringify({ keyInfo: { privateKey, address } });
}

/*
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
},
{
"path": "../transactions/tsconfig.build.json"
},
{
"path": "../wallet-sdk/tsconfig.build.json"
}
],
"include": ["src/**/*"]
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"dependencies": {
"@types/node": "^14.14.43",
"bn.js": "^5.2.0",
"bn.js": "^4.12.0",
"buffer": "^6.0.3",
"cross-fetch": "^3.1.4"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/keychain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
},
"dependencies": {
"@blockstack/rpc-client": "^0.3.0-alpha.11",
"@stacks/auth": "1.3.0-beta-3",
"@stacks/auth": "2.0.1",
"@stacks/common": "^2.0.1",
"@stacks/encryption": "^2.0.1",
"@stacks/network": "^1.2.2",
"@stacks/profile": "^1.2.3",
"@stacks/network": "^2.0.1",
"@stacks/profile": "^2.0.1",
"@stacks/storage": "^2.0.1",
"@stacks/transactions": "^2.0.1",
"@types/bn.js": "^4.11.6",
Expand All @@ -81,6 +81,6 @@
"jsontokens": "^3.0.0",
"randombytes": "^2.1.0",
"triplesec": "^4.0.3",
"zone-file": "^1.0.0"
"zone-file": "^2.0.0-beta.3"
}
}
11 changes: 0 additions & 11 deletions packages/keychain/src/types/zone-file.d.ts

This file was deleted.

6 changes: 5 additions & 1 deletion packages/keychain/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ export const getProfileURLFromZoneFile = async (name: string) => {
if (res.ok) {
const nameInfo: NameInfoResponse = await res.json();
const zone = parseZoneFile(nameInfo.zonefile);
return zone.uri[0].target;
const uri = zone.uri?.[0]?.target;
if (uri) {
return uri;
}
throw new Error(`No zonefile uri found: ${nameInfo.zonefile}`);
}
return;
};
4 changes: 2 additions & 2 deletions packages/profile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
},
"dependencies": {
"@stacks/common": "^2.0.1",
"@stacks/network": "^1.2.2",
"@stacks/network": "^2.0.1",
"@stacks/transactions": "^2.0.1",
"jsontokens": "^3.0.0",
"schema-inspector": "^2.0.1",
"zone-file": "^1.0.0"
"zone-file": "^2.0.0-beta.3"
},
"devDependencies": {
"@types/jest": "^26.0.22",
Expand Down
2 changes: 1 addition & 1 deletion packages/stacking/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@stacks/common": "^2.0.1",
"@stacks/network": "^1.2.2",
"@stacks/network": "^2.0.1",
"@stacks/stacks-blockchain-api-types": "^0.61.0",
"@stacks/transactions": "^2.0.1",
"@types/bn.js": "^4.11.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"url": "https://github.com/blockstack/blockstack.js/issues"
},
"dependencies": {
"@stacks/auth": "^1.2.3",
"@stacks/auth": "^2.0.1",
"@stacks/common": "^2.0.1",
"@stacks/encryption": "^2.0.1",
"bitcoinjs-lib": "^5.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/transactions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"dependencies": {
"@stacks/common": "^2.0.1",
"@stacks/network": "^1.2.2",
"@stacks/network": "^2.0.1",
"@types/bn.js": "^4.11.6",
"@types/elliptic": "^6.4.12",
"@types/node": "^14.14.43",
Expand Down

1 comment on commit f7d2c6c

@vercel
Copy link

@vercel vercel bot commented on f7d2c6c Aug 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.