Skip to content

Commit 82edcd0

Browse files
committed
Allow specifying other network bytes + docs
1 parent 0733fd7 commit 82edcd0

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ PIVX Promos avoid the pitfalls of [Brain Wallets](https://www.coindesk.com/tech/
2222

2323
## APIs
2424

25-
- `class` **PromoCode**: This is the main class of the library. It is used to create new promo codes. It accepts a single string parameter when creating a new instance of the class, which can either be a UUID-like code string, or human readable text.
25+
- `class` **PromoCode(code: string)**: This is the main class of the library. It is used to create new promo codes. It accepts a single string parameter when creating a new instance of the class, which can either be a UUID-like code string, or human readable text.
2626
- - `EventEmitter` **progressEmitter**: An event emitter that is called during the process of deriving a Promo Code's private key. It emits the `deriveProgress` event containing an object with two properties:
2727
- - - `number` **progress**: which represents the percentage completion of the process.
2828
- - - `number` **eta**: which represents the estimated seconds remaining until completion.
29-
- - `async function` **derivePrivateKey**: Starts the derivation of a Promo Code's private key. Once the private key has been derived, it returns an object containing the private key in raw bytes and WIF format:
29+
- - `async function` **derivePrivateKey(privatePrefix: number)**: Starts the derivation of a Promo Code's private key, it accepts an optional byte number for the coin's private key prefix. Once the private key has been derived, it returns an object containing the private key in raw bytes and WIF format:
3030
- - - `Uint8Array(32)` **bytes**: The unprocessed bytes of the Promo Code's private key.
3131
- - - `string` **wif**: The network-encoded WIF key of the Promo Code.
3232

@@ -59,3 +59,4 @@ promo.derivePrivateKey().then(cWallet => {
5959
## Implementation Notes:
6060
- The library user is expected to handle Public Key derivation themselves.
6161
- The library user must take care of Promo Code backwards compatibility upon `Target` primitive updates.
62+
- The library user may use another coin/network by specifying a Prefix Byte in `.derivePrivateKey(byte)`.

index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function dSHA256(data) {
8787
* @param {number} privatePrefix - One-byte WIF network prefix
8888
* @returns {PromoKey}
8989
*/
90-
export function encodePrivkey(pkBytes, privatePrefix = 212) {
90+
export function encodePrivkey(pkBytes, privatePrefix) {
9191
// Private Key Constants
9292
const pkNetBytesLen = pkBytes.length + 2;
9393
const pkNetBytes = new Uint8Array(pkNetBytesLen);
@@ -139,8 +139,9 @@ export class PromoCode {
139139

140140
/**
141141
* Derive a private key from the Promo Code (for Creation or Redemption)
142+
* @param {number} - The private network byte to use, default is PIVX Mainnet
142143
*/
143-
async derivePrivateKey() {
144+
async derivePrivateKey(privatePrefix = 212) {
144145
// Convert the string 'Promo Code' to a Uint8Array byte representation
145146
let arrByteCode = (new TextEncoder()).encode(this.code);
146147

@@ -175,8 +176,8 @@ export class PromoCode {
175176
}
176177
}
177178

178-
// Encode the millionth hash as a WIF Private Key (the 'wallet' of the Promo Code)
179-
const cWallet = encodePrivkey(arrByteCode);
179+
// Encode the final hash as a WIF Private Key (the 'wallet' of the Promo Code)
180+
const cWallet = encodePrivkey(arrByteCode, privatePrefix);
180181

181182
// Return it!
182183
return cWallet;

0 commit comments

Comments
 (0)