mirror of
https://github.com/alexgo-io/stacks.js.git
synced 2026-04-29 01:35:50 +08:00
feat: bring back cli command get_app_keys
This commit is contained in:
22435
package-lock.json
generated
22435
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -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"
|
||||
|
||||
@@ -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",
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
@@ -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',
|
||||
},
|
||||
|
||||
@@ -101,7 +101,6 @@ import {
|
||||
getpass,
|
||||
getBackupPhrase,
|
||||
mkdirs,
|
||||
getIDAddress,
|
||||
IDAppKeys,
|
||||
getIDAppKeys,
|
||||
makePromptsFromArgList,
|
||||
@@ -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;
|
||||
@@ -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 } });
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
},
|
||||
{
|
||||
"path": "../transactions/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../wallet-sdk/tsconfig.build.json"
|
||||
}
|
||||
],
|
||||
"include": ["src/**/*"]
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
@@ -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",
|
||||
@@ -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
packages/keychain/src/types/zone-file.d.ts
vendored
11
packages/keychain/src/types/zone-file.d.ts
vendored
@@ -1,11 +0,0 @@
|
||||
declare module 'zone-file' {
|
||||
interface URI {
|
||||
target: string;
|
||||
}
|
||||
export interface ZoneFile {
|
||||
$origin: string;
|
||||
uri: URI[];
|
||||
}
|
||||
|
||||
export const parseZoneFile: (zoneFile: string) => ZoneFile;
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
2463
packages/wallet-sdk/package-lock.json
generated
2463
packages/wallet-sdk/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -2,11 +2,11 @@
|
||||
"name": "@stacks/wallet-sdk",
|
||||
"version": "2.0.1",
|
||||
"description": "A library for generating Stacks blockchain wallets",
|
||||
"main": "./dist/index.js",
|
||||
"umd:main": "./dist/wallet-sdk.umd.production.js",
|
||||
"module": "./dist/wallet-sdk.esm.js",
|
||||
"main": "dist/index.js",
|
||||
"umd:main": "dist/index.umd.js",
|
||||
"module": "dist/esm/index.js",
|
||||
"author": "Hank Stoever",
|
||||
"types": "./dist/wallet-sdk/src/index.d.ts",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"start": "tsc -b tsconfig.build.json --watch --verbose",
|
||||
"build": "npm run clean && npm run build:cjs && npm run build:esm",
|
||||
@@ -29,7 +29,7 @@
|
||||
"depcheck": "depcheck --ignores='@types/*,eslint*,safe-buffer,codecov,@typescript-eslint/*,@blockstack/*'",
|
||||
"prepublishOnly": "npm run test && npm run build && npm run build:umd"
|
||||
},
|
||||
"unpkg": "./dist/wallet-sdk.cjs.production.min.js",
|
||||
"unpkg": "dist/index.umd.js",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"dist"
|
||||
@@ -45,18 +45,19 @@
|
||||
"@stacks/auth": "^2.0.1",
|
||||
"@stacks/common": "^2.0.1",
|
||||
"@stacks/encryption": "^2.0.1",
|
||||
"@stacks/network": "^2.0.1",
|
||||
"@stacks/profile": "^2.0.1",
|
||||
"@stacks/storage": "^2.0.1",
|
||||
"@stacks/transactions": "^2.0.1",
|
||||
"bip32": "2.0.6",
|
||||
"bip39": "^3.0.2",
|
||||
"bitcoinjs-lib": "^5.1.6",
|
||||
"bn.js": "^5.1.1",
|
||||
"c32check": "^1.0.1",
|
||||
"bn.js": "^4.12.0",
|
||||
"c32check": "^1.1.2",
|
||||
"jsontokens": "^3.0.0",
|
||||
"randombytes": "^2.1.0",
|
||||
"triplesec": "^3.0.27",
|
||||
"zone-file": "^1.0.0"
|
||||
"zone-file": "^2.0.0-beta.3"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
|
||||
11
packages/wallet-sdk/src/types/zone-file.d.ts
vendored
11
packages/wallet-sdk/src/types/zone-file.d.ts
vendored
@@ -1,11 +0,0 @@
|
||||
declare module 'zone-file' {
|
||||
interface URI {
|
||||
target: string;
|
||||
}
|
||||
export interface ZoneFile {
|
||||
$origin: string;
|
||||
uri: URI[];
|
||||
}
|
||||
|
||||
export const parseZoneFile: (zoneFile: string) => ZoneFile;
|
||||
}
|
||||
@@ -24,7 +24,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;
|
||||
};
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
},
|
||||
{
|
||||
"path": "../transactions/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../network/tsconfig.build.json"
|
||||
}
|
||||
],
|
||||
"include": ["src/**/*"]
|
||||
|
||||
Reference in New Issue
Block a user