Browse Source

:recycle: Public key zero byte

Add option to the getPublicKey function to allow get pubkey with zero byte at the begining or without it
Aleksey Popov 1 year ago
parent
commit
2bff4caef6
No account linked to committer's email address
1 changed files with 4 additions and 2 deletions
  1. 4
    2
      src/index.ts

+ 4
- 2
src/index.ts View File

@@ -50,10 +50,12 @@ const CKDPriv = ({ key, chainCode }: Keys, index: number): Keys => {
50 50
     };
51 51
 };
52 52
 
53
-export const getPublicKey = (privateKey: Buffer): Buffer => {
53
+export const getPublicKey = (privateKey: Buffer, withZeroByte = true): Buffer => {
54 54
     const { signPk } = naclInstance.crypto_sign_seed_keypair(privateKey);
55 55
     const zero = Buffer.alloc(1, 0);
56
-    return Buffer.concat([zero, Buffer.from(signPk)]);
56
+    return withZeroByte ?
57
+        Buffer.concat([zero, Buffer.from(signPk)]) :
58
+        Buffer.from(signPk);
57 59
 };
58 60
 
59 61
 export const isValidPath = (path: string): boolean => {

Loading…
Cancel
Save