Browse Source

npm bump

master
peter 2 years ago
parent
commit
82cff57485
2 changed files with 21 additions and 21 deletions
  1. 20
    20
      hdkey.ts
  2. 1
    1
      package.json

+ 20
- 20
hdkey.ts View File

@@ -3,12 +3,12 @@ const bitcoin = require('bitcoinjs-lib');
3 3
 const bip39 = require('bip39')
4 4
 const assert = require('bsert');
5 5
 
6
-export type network = 'testnet' | 'mainnet'
7
-export type keyType =  "public" | "private"
6
+type network = 'testnet' | 'mainnet'
7
+type keyType =  "public" | "private"
8 8
 /**
9 9
  * Generate a BIP39 menemonic
10 10
  */
11
-export function  randomMenemonic():string{
11
+function  randomMenemonic():string{
12 12
     return bip39.generateMnemonic()
13 13
 }
14 14
 
@@ -16,7 +16,7 @@ export function  randomMenemonic():string{
16 16
  * Generate a pseudo-random seed from BIP39 menemonic
17 17
  * @param menemonic 
18 18
  */
19
-export function  seedFromMenemonic(menemonic:string):string{
19
+function  seedFromMenemonic(menemonic:string):string{
20 20
     assert(bip39.validateMnemonic(menemonic))
21 21
     return bip39.mnemonicToSeedSync(menemonic).toString('hex')
22 22
 }
@@ -27,7 +27,7 @@ export function  seedFromMenemonic(menemonic:string):string{
27 27
  * @param net Network to use ("testnet", "mainnet")
28 28
  * @param n n-th derived keypair default:0
29 29
  */
30
-export function  deriveAccount(seed:string, net:network = "mainnet", n:number = 0):{publicExtendedKey:string, privateExtendedKey:string}{
30
+function  deriveAccount(seed:string, net:network = "mainnet", n:number = 0):{publicExtendedKey:string, privateExtendedKey:string}{
31 31
     assert(n >= 0)
32 32
 
33 33
     let version
@@ -55,7 +55,7 @@ export function  deriveAccount(seed:string, net:network = "mainnet", n:number =
55 55
  * @param networkName Network to use ("testnet", "mainnet")
56 56
  * @param n n-th derived address default:0
57 57
  */
58
-export function  generateAddress(extendedKey:string, n:number = 0):string{
58
+function  generateAddress(extendedKey:string, n:number = 0):string{
59 59
     assert(n >= 0)
60 60
     let version
61 61
     let t = checkHDKey(extendedKey)
@@ -72,7 +72,7 @@ export function  generateAddress(extendedKey:string, n:number = 0):string{
72 72
 }
73 73
 
74 74
 
75
-export function  HDKeyFromExtendedKey(extendedKeyB58: string): any | false{
75
+function  HDKeyFromExtendedKey(extendedKeyB58: string): any | false{
76 76
     let hdkey
77 77
     let version
78 78
     let t = checkHDKey(extendedKeyB58)
@@ -90,7 +90,7 @@ export function  HDKeyFromExtendedKey(extendedKeyB58: string): any | false{
90 90
     return hdkey
91 91
 }
92 92
 
93
-export function  checkHDKey(key: string): {net: network, type: keyType} | false{
93
+function  checkHDKey(key: string): {net: network, type: keyType} | false{
94 94
     if(key.startsWith('x')){
95 95
         if(key.startsWith('xpub')){
96 96
             return {net:'mainnet', type: 'public'}
@@ -108,7 +108,7 @@ export function  checkHDKey(key: string): {net: network, type: keyType} | false{
108 108
     return false
109 109
 }
110 110
 
111
-export function  deriveAddress(extendedKey: string, n: number, derivationPrefix = 'm/0/'): string | false{
111
+function  deriveAddress(extendedKey: string, n: number, derivationPrefix = 'm/0/'): string | false{
112 112
     let t = checkHDKey(extendedKey)
113 113
     let childkey = deriveKey(extendedKey, n, derivationPrefix)
114 114
     if(!t || !childkey){
@@ -117,7 +117,7 @@ export function  deriveAddress(extendedKey: string, n: number, derivationPrefix
117 117
     return addressFromHDKey(childkey._publicKey, t.net)
118 118
 }
119 119
 
120
-export function  deriveKey(extendedKey: string, n: number, derivationPrefix = 'm/0/'): any | false{
120
+function  deriveKey(extendedKey: string, n: number, derivationPrefix = 'm/0/'): any | false{
121 121
     let t = checkHDKey(extendedKey)
122 122
     let hdkey = HDKeyFromExtendedKey(extendedKey)
123 123
     if(!t || !hdkey){
@@ -126,17 +126,17 @@ export function  deriveKey(extendedKey: string, n: number, derivationPrefix = 'm
126 126
     return hdkey.derive(derivationPrefix+n)
127 127
 }
128 128
 
129
-export function  addressFromHDKey(hdkey:string, net: network = "mainnet"){
129
+function  addressFromHDKey(hdkey:string, net: network = "mainnet"){
130 130
     return <string>bitcoin.payments.p2pkh({ pubkey: Buffer.from(hdkey), network: bitcoin.networks[net] }).address
131 131
 }
132 132
 
133
-export default {
134
-    addressFromHDKey: addressFromHDKey,
135
-    deriveAccount: deriveAccount,
136
-    deriveAddress: deriveAddress,
137
-    generateAddress: generateAddress,
138
-    HDKeyFromExtendedKey: HDKeyFromExtendedKey,
139
-    seedFromMenemonic: seedFromMenemonic,
140
-    randomMenemonic: randomMenemonic,
141
-    checkHDKey: checkHDKey
133
+export const hdkey = {
134
+    "addressFromHDKey": addressFromHDKey,
135
+    "deriveAccount": deriveAccount,
136
+    "deriveAddress": deriveAddress,
137
+    "generateAddress": generateAddress,
138
+    "HDKeyFromExtendedKey": HDKeyFromExtendedKey,
139
+    "seedFromMenemonic": seedFromMenemonic,
140
+    "randomMenemonic": randomMenemonic,
141
+    "checkHDKey": checkHDKey
142 142
 }

+ 1
- 1
package.json View File

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "btc-hdkey",
3
-  "version": "0.0.10",
3
+  "version": "0.0.11",
4 4
   "description": "Hierarchical Deterministic Wallet support for BTC",
5 5
   "main": "hdkey.min.js",
6 6
   "types": "hdkey.d.ts",

Loading…
Cancel
Save