paytaca-cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +142 -0
- package/bin/paytaca.js +2 -0
- package/dist/commands/address.d.ts +10 -0
- package/dist/commands/address.d.ts.map +1 -0
- package/dist/commands/address.js +72 -0
- package/dist/commands/address.js.map +1 -0
- package/dist/commands/balance.d.ts +10 -0
- package/dist/commands/balance.d.ts.map +1 -0
- package/dist/commands/balance.js +70 -0
- package/dist/commands/balance.js.map +1 -0
- package/dist/commands/history.d.ts +10 -0
- package/dist/commands/history.d.ts.map +1 -0
- package/dist/commands/history.js +114 -0
- package/dist/commands/history.js.map +1 -0
- package/dist/commands/receive.d.ts +10 -0
- package/dist/commands/receive.d.ts.map +1 -0
- package/dist/commands/receive.js +54 -0
- package/dist/commands/receive.js.map +1 -0
- package/dist/commands/send.d.ts +18 -0
- package/dist/commands/send.d.ts.map +1 -0
- package/dist/commands/send.js +94 -0
- package/dist/commands/send.js.map +1 -0
- package/dist/commands/wallet.d.ts +11 -0
- package/dist/commands/wallet.d.ts.map +1 -0
- package/dist/commands/wallet.js +151 -0
- package/dist/commands/wallet.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/storage/keychain.d.ts +56 -0
- package/dist/storage/keychain.d.ts.map +1 -0
- package/dist/storage/keychain.js +92 -0
- package/dist/storage/keychain.js.map +1 -0
- package/dist/utils/crypto.d.ts +23 -0
- package/dist/utils/crypto.d.ts.map +1 -0
- package/dist/utils/crypto.js +68 -0
- package/dist/utils/crypto.js.map +1 -0
- package/dist/utils/network.d.ts +27 -0
- package/dist/utils/network.d.ts.map +1 -0
- package/dist/utils/network.js +45 -0
- package/dist/utils/network.js.map +1 -0
- package/dist/wallet/bch.d.ts +137 -0
- package/dist/wallet/bch.d.ts.map +1 -0
- package/dist/wallet/bch.js +197 -0
- package/dist/wallet/bch.js.map +1 -0
- package/dist/wallet/index.d.ts +72 -0
- package/dist/wallet/index.d.ts.map +1 -0
- package/dist/wallet/index.js +120 -0
- package/dist/wallet/index.js.map +1 -0
- package/dist/wallet/keys.d.ts +69 -0
- package/dist/wallet/keys.d.ts.map +1 -0
- package/dist/wallet/keys.js +125 -0
- package/dist/wallet/keys.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HD key derivation for Bitcoin Cash using libauth.
|
|
3
|
+
*
|
|
4
|
+
* Adapted from: paytaca-app/src/wallet/bch-libauth.js (LibauthHDWallet class)
|
|
5
|
+
*
|
|
6
|
+
* This is the modern derivation implementation that uses @bitauth/libauth
|
|
7
|
+
* and bip39 directly, without @psf/bch-js.
|
|
8
|
+
*
|
|
9
|
+
* Derivation path: m/44'/145'/0' (BIP44, coin type 145 = BCH)
|
|
10
|
+
* - Receiving addresses: m/44'/145'/0'/0/{index}
|
|
11
|
+
* - Change addresses: m/44'/145'/0'/1/{index}
|
|
12
|
+
*/
|
|
13
|
+
import { mnemonicToSeedSync } from 'bip39';
|
|
14
|
+
import { binToHex, deriveHdPath, deriveHdPrivateNodeFromSeed, deriveHdPublicNode, encodePrivateKeyWif, sha256, } from '@bitauth/libauth';
|
|
15
|
+
import { pubkeyToAddress, toTokenAddress } from '../utils/crypto.js';
|
|
16
|
+
import { BCH_DERIVATION_PATH } from '../utils/network.js';
|
|
17
|
+
export class LibauthHDWallet {
|
|
18
|
+
mnemonic;
|
|
19
|
+
derivationPath;
|
|
20
|
+
network;
|
|
21
|
+
walletHash;
|
|
22
|
+
/**
|
|
23
|
+
* @param mnemonic - BIP39 mnemonic phrase
|
|
24
|
+
* @param derivationPath - HD derivation path (default: m/44'/145'/0')
|
|
25
|
+
* @param network - 'mainnet' or 'chipnet'
|
|
26
|
+
*/
|
|
27
|
+
constructor(mnemonic = '', derivationPath = BCH_DERIVATION_PATH, network = 'mainnet') {
|
|
28
|
+
this.mnemonic = mnemonic;
|
|
29
|
+
this.derivationPath = derivationPath;
|
|
30
|
+
this.network = network;
|
|
31
|
+
this.walletHash = this.getWalletHash();
|
|
32
|
+
}
|
|
33
|
+
get isChipnet() {
|
|
34
|
+
return this.network === 'chipnet';
|
|
35
|
+
}
|
|
36
|
+
set isChipnet(value) {
|
|
37
|
+
this.network = value ? 'chipnet' : 'mainnet';
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Compute wallet hash: sha256(sha256(mnemonic) + sha256(derivationPath))
|
|
41
|
+
* Identical to paytaca-app's computeWalletHash() and BchWallet.getWalletHash()
|
|
42
|
+
*/
|
|
43
|
+
getWalletHash() {
|
|
44
|
+
const customSha256 = (value) => binToHex(sha256.hash(Buffer.from(value, 'utf8')));
|
|
45
|
+
const mnemonicHash = customSha256(this.mnemonic);
|
|
46
|
+
const derivationPathHash = customSha256(this.derivationPath);
|
|
47
|
+
const walletHash = customSha256(mnemonicHash + derivationPathHash);
|
|
48
|
+
return walletHash;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Derive the main HD node at the derivation path.
|
|
52
|
+
* mnemonic → seed → master node → derive(path)
|
|
53
|
+
*/
|
|
54
|
+
getMainNode() {
|
|
55
|
+
const mnemonicBin = new Uint8Array(mnemonicToSeedSync(this.mnemonic));
|
|
56
|
+
const node = deriveHdPrivateNodeFromSeed(mnemonicBin);
|
|
57
|
+
if (!('valid' in node) || !node.valid) {
|
|
58
|
+
throw new Error('Failed to derive valid HD node from seed');
|
|
59
|
+
}
|
|
60
|
+
const mainNode = deriveHdPath(node, this.derivationPath);
|
|
61
|
+
if (typeof mainNode === 'string')
|
|
62
|
+
throw new Error(mainNode);
|
|
63
|
+
if (!('privateKey' in mainNode)) {
|
|
64
|
+
throw new Error('Derivation produced a public node instead of private node');
|
|
65
|
+
}
|
|
66
|
+
return mainNode;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Derive an HD node at a relative sub-path from the main node.
|
|
70
|
+
* @param path - Relative path like '0/0' for receiving index 0
|
|
71
|
+
*/
|
|
72
|
+
getNodeAt(path = '') {
|
|
73
|
+
if (!path?.startsWith('m/') && !path.startsWith('M/'))
|
|
74
|
+
path = 'm/' + path;
|
|
75
|
+
if (!path?.startsWith('m') && !path.startsWith('M'))
|
|
76
|
+
path = 'm' + path;
|
|
77
|
+
const mainNode = this.getMainNode();
|
|
78
|
+
const node = deriveHdPath(mainNode, path);
|
|
79
|
+
if (typeof node === 'string')
|
|
80
|
+
throw new Error(node);
|
|
81
|
+
if (!('privateKey' in node)) {
|
|
82
|
+
throw new Error('Derivation produced a public node instead of private node');
|
|
83
|
+
}
|
|
84
|
+
return node;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get the WIF-encoded private key at a sub-path.
|
|
88
|
+
*/
|
|
89
|
+
getPrivateKeyWifAt(path = '') {
|
|
90
|
+
const node = this.getNodeAt(path);
|
|
91
|
+
return encodePrivateKeyWif(node.privateKey, 'mainnet');
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get the compressed public key (hex) at a sub-path.
|
|
95
|
+
*/
|
|
96
|
+
getPubkeyAt(path = '') {
|
|
97
|
+
const node = this.getNodeAt(path);
|
|
98
|
+
const publicNode = deriveHdPublicNode(node);
|
|
99
|
+
return binToHex(publicNode.publicKey);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Derive a CashAddress at a sub-path.
|
|
103
|
+
*
|
|
104
|
+
* @param opts.path - Sub-path like '0/0' (receiving) or '1/0' (change)
|
|
105
|
+
* @param opts.token - If true, return token-aware address (z-prefix)
|
|
106
|
+
*/
|
|
107
|
+
getAddressAt(opts = {}) {
|
|
108
|
+
const pubkeyHex = this.getPubkeyAt(opts?.path);
|
|
109
|
+
const address = pubkeyToAddress(pubkeyHex, this.isChipnet);
|
|
110
|
+
if (opts?.token)
|
|
111
|
+
return toTokenAddress(address);
|
|
112
|
+
return address;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Derive receiving and change addresses at a given index.
|
|
116
|
+
* Convenience method matching BchWallet.getAddressSetAt() from paytaca-app.
|
|
117
|
+
*/
|
|
118
|
+
getAddressSetAt(index) {
|
|
119
|
+
return {
|
|
120
|
+
receiving: this.getAddressAt({ path: `0/${index}` }),
|
|
121
|
+
change: this.getAddressAt({ path: `1/${index}` }),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../src/wallet/keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,2BAA2B,EAC3B,kBAAkB,EAClB,mBAAmB,EACnB,MAAM,GAEP,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAEzD,MAAM,OAAO,eAAe;IAC1B,QAAQ,CAAQ;IAChB,cAAc,CAAQ;IACtB,OAAO,CAAuB;IAC9B,UAAU,CAAQ;IAElB;;;;OAIG;IACH,YACE,WAAmB,EAAE,EACrB,iBAAyB,mBAAmB,EAC5C,UAAiC,SAAS;QAE1C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;QACpC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,aAAa,EAAE,CAAA;IACxC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO,KAAK,SAAS,CAAA;IACnC,CAAC;IAED,IAAI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AAO,GAAG,eAAe,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;QAC1D,IAAI,IAAI,EAAE,KAAK;YAAE,OAAO,cAAc,CAAC,OAAO,CAAC,CAAA;QAC/C,OAAO,OAAO,CAAA;IAChB,CAAC;IAED;;;OAGG;IACH,eAAe,CAAC,KAAa;QAC3B,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,KAAK,KAAK,EAAE,EAAE,CAAC;YACpD,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,KAAK,KAAK,EAAE,EAAE,CAAC;SAClD,CAAA;IACH,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "paytaca-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Command-line interface for the Paytaca Bitcoin Cash wallet",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"paytaca": "./bin/paytaca.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"bin/",
|
|
13
|
+
"dist/",
|
|
14
|
+
"LICENSE",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"dev": "tsc --watch",
|
|
20
|
+
"start": "node bin/paytaca.js",
|
|
21
|
+
"clean": "rm -rf dist",
|
|
22
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"bitcoin-cash",
|
|
26
|
+
"bch",
|
|
27
|
+
"wallet",
|
|
28
|
+
"cli",
|
|
29
|
+
"paytaca",
|
|
30
|
+
"cryptocurrency"
|
|
31
|
+
],
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/paytaca/paytaca-cli.git"
|
|
35
|
+
},
|
|
36
|
+
"author": "Paytaca",
|
|
37
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@bitauth/libauth": "2.0.0-alpha.8",
|
|
40
|
+
"@napi-rs/keyring": "^1.2.0",
|
|
41
|
+
"bip39": "^3.1.0",
|
|
42
|
+
"chalk": "^5.4.1",
|
|
43
|
+
"commander": "^12.1.0",
|
|
44
|
+
"js-sha256": "^0.9.0",
|
|
45
|
+
"qrcode-terminal": "^0.12.0",
|
|
46
|
+
"watchtower-cash-js": "^0.2.4"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^22.0.0",
|
|
50
|
+
"@types/qrcode-terminal": "^0.12.2",
|
|
51
|
+
"typescript": "^5.9.3"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=20.0.0"
|
|
55
|
+
}
|
|
56
|
+
}
|