@decryption/wallet 0.2.0 → 0.4.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/README.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @decryption/wallet
2
2
 
3
+ <p align="center" width="100%">
4
+ <img height="250" src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" />
5
+ </p>
6
+
7
+ <p align="center" width="100%">
8
+ <a href="https://github.com/constructive-io/decryption/actions/workflows/ci.yml">
9
+ <img height="20" src="https://github.com/constructive-io/decryption/actions/workflows/ci.yml/badge.svg" />
10
+ </a>
11
+ <a href="https://www.npmjs.com/package/@decryption/wallet"><img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/decryption?filename=packages%2Fwallet%2Fpackage.json"/></a>
12
+ </p>
13
+
14
+
3
15
  BIP39 mnemonics, BIP32 derivation and address encoding — entirely offline. This package has no
4
16
  chain registry, no RPC client and no transaction signing: it turns a mnemonic into addresses and
5
17
  stops there.
package/esm/networks.js CHANGED
@@ -5,8 +5,24 @@ const cosmos = (id, name, prefix, coinType = 118) => ({
5
5
  addressEncoding: 'bech32',
6
6
  prefix,
7
7
  });
8
- /** Built-in networks. Anything missing can be supplied with {@link defineNetwork}. */
8
+ /**
9
+ * Built-in networks, in presentation order: Bitcoin, then Ethereum, then the rest.
10
+ * Anything missing can be supplied with {@link defineNetwork}.
11
+ */
9
12
  export const NETWORKS = {
13
+ bitcoin: {
14
+ id: 'bitcoin',
15
+ name: 'Bitcoin',
16
+ coinType: 0,
17
+ addressEncoding: 'p2wpkh',
18
+ prefix: 'bc',
19
+ },
20
+ ethereum: {
21
+ id: 'ethereum',
22
+ name: 'Ethereum',
23
+ coinType: 60,
24
+ addressEncoding: 'evm',
25
+ },
10
26
  cosmoshub: cosmos('cosmoshub', 'Cosmos Hub', 'cosmos'),
11
27
  osmosis: cosmos('osmosis', 'Osmosis', 'osmo'),
12
28
  juno: cosmos('juno', 'Juno', 'juno'),
@@ -15,20 +31,11 @@ export const NETWORKS = {
15
31
  celestia: cosmos('celestia', 'Celestia', 'celestia'),
16
32
  secret: cosmos('secret', 'Secret Network', 'secret', 529),
17
33
  terra: cosmos('terra', 'Terra', 'terra', 330),
18
- ethereum: {
19
- id: 'ethereum',
20
- name: 'Ethereum',
21
- coinType: 60,
22
- addressEncoding: 'evm',
23
- },
24
- bitcoin: {
25
- id: 'bitcoin',
26
- name: 'Bitcoin',
27
- coinType: 0,
28
- addressEncoding: 'p2wpkh',
29
- prefix: 'bc',
30
- },
31
34
  };
35
+ /** The network used when the caller does not name one. */
36
+ export const DEFAULT_NETWORK = 'bitcoin';
37
+ /** Network ids in presentation order. */
38
+ export const NETWORK_IDS = Object.keys(NETWORKS);
32
39
  /**
33
40
  * Builds a network definition for a chain that is not built in — the common case for
34
41
  * cosmos-family chains, which differ only by bech32 prefix and coin type.
package/esm/wallet.js CHANGED
@@ -2,7 +2,7 @@ import { HDKey } from '@decryption/bip32';
2
2
  import { bytesToHex } from '@decryption/hashes/utils';
3
3
  import { publicKeyToAddress } from './address';
4
4
  import { createMnemonic, mnemonicToSeed } from './mnemonic';
5
- import { derivationPath, resolveNetwork } from './networks';
5
+ import { DEFAULT_NETWORK, derivationPath, resolveNetwork } from './networks';
6
6
  /** Derives one account. The private key never leaves this function. */
7
7
  export const deriveAccount = (mnemonic, network, options = {}) => {
8
8
  const resolved = resolveNetwork(network);
@@ -36,7 +36,7 @@ export const derivePrivateKey = (mnemonic, network, options = {}) => {
36
36
  /** Derives the same account index across several networks — the usual "show me my addresses" view. */
37
37
  export const deriveAccounts = (mnemonic, networks, options = {}) => networks.map((network) => deriveAccount(mnemonic, network, options));
38
38
  /** Generates a new mnemonic and derives its first account on each requested network. */
39
- export const createWallet = (networks = ['cosmoshub'], words = 24, options = {}) => {
39
+ export const createWallet = (networks = [DEFAULT_NETWORK], words = 24, options = {}) => {
40
40
  const mnemonic = createMnemonic(words);
41
41
  return { mnemonic, accounts: deriveAccounts(mnemonic, networks, options) };
42
42
  };
package/networks.d.ts CHANGED
@@ -14,8 +14,15 @@ export interface Network {
14
14
  /** Bech32 human-readable part, for `bech32` and `p2wpkh` encodings. */
15
15
  prefix?: string;
16
16
  }
17
- /** Built-in networks. Anything missing can be supplied with {@link defineNetwork}. */
17
+ /**
18
+ * Built-in networks, in presentation order: Bitcoin, then Ethereum, then the rest.
19
+ * Anything missing can be supplied with {@link defineNetwork}.
20
+ */
18
21
  export declare const NETWORKS: Record<string, Network>;
22
+ /** The network used when the caller does not name one. */
23
+ export declare const DEFAULT_NETWORK = "bitcoin";
24
+ /** Network ids in presentation order. */
25
+ export declare const NETWORK_IDS: string[];
19
26
  /**
20
27
  * Builds a network definition for a chain that is not built in — the common case for
21
28
  * cosmos-family chains, which differ only by bech32 prefix and coin type.
package/networks.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.derivationPath = exports.resolveNetwork = exports.defineNetwork = exports.NETWORKS = void 0;
3
+ exports.derivationPath = exports.resolveNetwork = exports.defineNetwork = exports.NETWORK_IDS = exports.DEFAULT_NETWORK = exports.NETWORKS = void 0;
4
4
  const cosmos = (id, name, prefix, coinType = 118) => ({
5
5
  id,
6
6
  name,
@@ -8,8 +8,24 @@ const cosmos = (id, name, prefix, coinType = 118) => ({
8
8
  addressEncoding: 'bech32',
9
9
  prefix,
10
10
  });
11
- /** Built-in networks. Anything missing can be supplied with {@link defineNetwork}. */
11
+ /**
12
+ * Built-in networks, in presentation order: Bitcoin, then Ethereum, then the rest.
13
+ * Anything missing can be supplied with {@link defineNetwork}.
14
+ */
12
15
  exports.NETWORKS = {
16
+ bitcoin: {
17
+ id: 'bitcoin',
18
+ name: 'Bitcoin',
19
+ coinType: 0,
20
+ addressEncoding: 'p2wpkh',
21
+ prefix: 'bc',
22
+ },
23
+ ethereum: {
24
+ id: 'ethereum',
25
+ name: 'Ethereum',
26
+ coinType: 60,
27
+ addressEncoding: 'evm',
28
+ },
13
29
  cosmoshub: cosmos('cosmoshub', 'Cosmos Hub', 'cosmos'),
14
30
  osmosis: cosmos('osmosis', 'Osmosis', 'osmo'),
15
31
  juno: cosmos('juno', 'Juno', 'juno'),
@@ -18,20 +34,11 @@ exports.NETWORKS = {
18
34
  celestia: cosmos('celestia', 'Celestia', 'celestia'),
19
35
  secret: cosmos('secret', 'Secret Network', 'secret', 529),
20
36
  terra: cosmos('terra', 'Terra', 'terra', 330),
21
- ethereum: {
22
- id: 'ethereum',
23
- name: 'Ethereum',
24
- coinType: 60,
25
- addressEncoding: 'evm',
26
- },
27
- bitcoin: {
28
- id: 'bitcoin',
29
- name: 'Bitcoin',
30
- coinType: 0,
31
- addressEncoding: 'p2wpkh',
32
- prefix: 'bc',
33
- },
34
37
  };
38
+ /** The network used when the caller does not name one. */
39
+ exports.DEFAULT_NETWORK = 'bitcoin';
40
+ /** Network ids in presentation order. */
41
+ exports.NETWORK_IDS = Object.keys(exports.NETWORKS);
35
42
  /**
36
43
  * Builds a network definition for a chain that is not built in — the common case for
37
44
  * cosmos-family chains, which differ only by bech32 prefix and coin type.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decryption/wallet",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Offline BIP39/BIP32 wallets and address derivation for cosmos-family, EVM and Bitcoin",
5
5
  "author": "Constructive <developers@constructive.io>",
6
6
  "main": "index.js",
@@ -39,14 +39,14 @@
39
39
  "offline"
40
40
  ],
41
41
  "dependencies": {
42
- "@decryption/base": "0.2.0",
43
- "@decryption/bip32": "0.2.0",
44
- "@decryption/bip39": "0.2.0",
45
- "@decryption/curves": "0.2.0",
46
- "@decryption/hashes": "0.2.0"
42
+ "@decryption/base": "0.4.0",
43
+ "@decryption/bip32": "0.4.0",
44
+ "@decryption/bip39": "0.4.0",
45
+ "@decryption/curves": "0.4.0",
46
+ "@decryption/hashes": "0.4.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "makage": "0.3.0"
50
50
  },
51
- "gitHead": "8d85fbfdbb1d57da93e99904a03e6e8d8531d281"
51
+ "gitHead": "49eff05f5fa934d2d045372f0ddb4626190822dd"
52
52
  }
package/wallet.js CHANGED
@@ -42,7 +42,7 @@ exports.derivePrivateKey = derivePrivateKey;
42
42
  const deriveAccounts = (mnemonic, networks, options = {}) => networks.map((network) => (0, exports.deriveAccount)(mnemonic, network, options));
43
43
  exports.deriveAccounts = deriveAccounts;
44
44
  /** Generates a new mnemonic and derives its first account on each requested network. */
45
- const createWallet = (networks = ['cosmoshub'], words = 24, options = {}) => {
45
+ const createWallet = (networks = [networks_1.DEFAULT_NETWORK], words = 24, options = {}) => {
46
46
  const mnemonic = (0, mnemonic_1.createMnemonic)(words);
47
47
  return { mnemonic, accounts: (0, exports.deriveAccounts)(mnemonic, networks, options) };
48
48
  };