Skip to content

Commit c50c823

Browse files
committed
chore: include dist/ directory in version control
- Remove dist/ from .gitignore as this is a library package - Add compiled output for both ESM and CommonJS formats - Include source maps and type definitions
1 parent 9b06f85 commit c50c823

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+6145
-3
lines changed

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ npm-debug.log*
44
yarn-debug.log*
55
yarn-error.log*
66

7-
# Build output
8-
dist/
9-
build/
7+
# Build artifacts
108
*.tsbuildinfo
9+
*.tgz
1110

1211
# IDE and editor files
1312
.idea/
@@ -23,3 +22,6 @@ coverage/
2322
.env
2423
.env.local
2524
.env.*.local
25+
26+
# Project specific
27+
CHECKLIST.md

dist/__mocks__/@noble/secp256k1.d.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { bytesToHex as originalBytesToHex, hexToBytes as originalHexToBytes } from "@noble/hashes/utils";
2+
export declare function getPublicKey(privateKey: Uint8Array | string): Uint8Array;
3+
export declare const schnorr: {
4+
sign(message: Uint8Array | string, privateKey: Uint8Array | string): Promise<Uint8Array>;
5+
verify(signature: Uint8Array | string, message: Uint8Array | string, publicKey: Uint8Array | string): Promise<boolean>;
6+
};
7+
export declare const utils: {
8+
bytesToHex: typeof originalBytesToHex;
9+
hexToBytes: typeof originalHexToBytes;
10+
isValidPrivateKey(key: Uint8Array | string): boolean;
11+
randomPrivateKey(): Uint8Array;
12+
};
13+
declare const _default: {
14+
getPublicKey: typeof getPublicKey;
15+
schnorr: {
16+
sign(message: Uint8Array | string, privateKey: Uint8Array | string): Promise<Uint8Array>;
17+
verify(signature: Uint8Array | string, message: Uint8Array | string, publicKey: Uint8Array | string): Promise<boolean>;
18+
};
19+
utils: {
20+
bytesToHex: typeof originalBytesToHex;
21+
hexToBytes: typeof originalHexToBytes;
22+
isValidPrivateKey(key: Uint8Array | string): boolean;
23+
randomPrivateKey(): Uint8Array;
24+
};
25+
};
26+
export default _default;

dist/__mocks__/@noble/secp256k1.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Mock implementation of @noble/secp256k1 for testing
2+
import { bytesToHex as originalBytesToHex, hexToBytes as originalHexToBytes } from "@noble/hashes/utils";
3+
function ensureUint8Array(input) {
4+
if (input instanceof Uint8Array)
5+
return input;
6+
if (typeof input === 'string')
7+
return originalHexToBytes(input);
8+
throw new Error('Input must be Uint8Array or hex string');
9+
}
10+
function createMockPublicKey(privateKey) {
11+
// Create a deterministic 33-byte compressed public key
12+
const mockPubKey = new Uint8Array(33);
13+
mockPubKey[0] = 0x02; // Compressed format prefix
14+
// Use private key to generate a deterministic public key
15+
for (let i = 0; i < 32; i++) {
16+
mockPubKey[i + 1] = privateKey[i] ^ 0x02; // XOR with 0x02 to make it different from private key
17+
}
18+
return mockPubKey;
19+
}
20+
// Mock point multiplication for public key derivation
21+
export function getPublicKey(privateKey) {
22+
const privKeyBytes = ensureUint8Array(privateKey);
23+
if (privKeyBytes.length !== 32) {
24+
throw new Error('Private key must be 32 bytes');
25+
}
26+
return createMockPublicKey(privKeyBytes);
27+
}
28+
// Mock signature creation
29+
export const schnorr = {
30+
sign(message, privateKey) {
31+
const msgBytes = ensureUint8Array(message);
32+
const privKeyBytes = ensureUint8Array(privateKey);
33+
const signature = new Uint8Array(64);
34+
// Create a deterministic signature
35+
for (let i = 0; i < 32; i++) {
36+
signature[i] = msgBytes[i % msgBytes.length];
37+
signature[i + 32] = privKeyBytes[i];
38+
}
39+
return Promise.resolve(signature);
40+
},
41+
verify(signature, message, publicKey) {
42+
return Promise.resolve(true);
43+
}
44+
};
45+
// Mock utility functions
46+
export const utils = {
47+
bytesToHex: originalBytesToHex,
48+
hexToBytes: originalHexToBytes,
49+
isValidPrivateKey(key) {
50+
try {
51+
const keyBytes = ensureUint8Array(key);
52+
return keyBytes.length === 32;
53+
}
54+
catch {
55+
return false;
56+
}
57+
},
58+
randomPrivateKey() {
59+
const privateKey = new Uint8Array(32);
60+
for (let i = 0; i < 32; i++) {
61+
privateKey[i] = Math.floor(Math.random() * 256);
62+
}
63+
return privateKey;
64+
}
65+
};
66+
export default {
67+
getPublicKey,
68+
schnorr,
69+
utils
70+
};

dist/__mocks__/bech32.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
declare function toWords(data: Uint8Array): number[];
2+
declare function fromWords(words: number[]): number[];
3+
declare function encode(prefix: string, words: number[], limit: number): string;
4+
declare function decode(str: string, limit?: number): {
5+
prefix: string;
6+
words: number[];
7+
};
8+
export declare const bech32: {
9+
toWords: typeof toWords;
10+
fromWords: typeof fromWords;
11+
encode: typeof encode;
12+
decode: typeof decode;
13+
};
14+
export {};

dist/__mocks__/bech32.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Mock implementation of bech32 for testing
2+
import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
3+
function toWords(data) {
4+
// Convert bytes to 5-bit words
5+
const words = [];
6+
for (let i = 0; i < data.length; i++) {
7+
words.push(data[i] & 0x1f); // Take the lower 5 bits
8+
}
9+
return words;
10+
}
11+
function fromWords(words) {
12+
// Convert 5-bit words back to bytes
13+
// Return number[] to match real bech32 library behavior
14+
const data = new Uint8Array(words.length);
15+
for (let i = 0; i < words.length; i++) {
16+
data[i] = words[i] & 0xff;
17+
}
18+
return Array.from(data);
19+
}
20+
function encode(prefix, words, limit) {
21+
// Simple mock encoding: prefix1<hex>
22+
const data = Uint8Array.from(words);
23+
return `${prefix}1${bytesToHex(data)}`;
24+
}
25+
function decode(str, limit) {
26+
// Simple mock decoding: split on '1'
27+
const [prefix, data] = str.split('1');
28+
if (!prefix || !data) {
29+
throw new Error('Invalid bech32 string');
30+
}
31+
const bytes = hexToBytes(data);
32+
return {
33+
prefix,
34+
words: Array.from(bytes).map(b => b & 0x1f) // Convert to 5-bit words
35+
};
36+
}
37+
export const bech32 = {
38+
toWords,
39+
fromWords,
40+
encode,
41+
decode
42+
};

dist/__mocks__/bip39.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export declare function generateMnemonic(): string;
2+
export declare function validateMnemonic(mnemonic: string): boolean;
3+
export declare function mnemonicToEntropy(mnemonic: string): string;

dist/__mocks__/bip39.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Mock implementation of bip39 for testing
2+
import { bytesToHex } from "@noble/hashes/utils";
3+
const VALID_SEED_PHRASE = "witch collapse practice feed shame open despair creek road again ice least";
4+
const VALID_ENTROPY = "000102030405060708090a0b0c0d0e0f";
5+
export function generateMnemonic() {
6+
return VALID_SEED_PHRASE;
7+
}
8+
export function validateMnemonic(mnemonic) {
9+
console.log("Mock validateMnemonic called with:", mnemonic);
10+
// Accept the specific test mnemonic or any 12-word phrase
11+
if (mnemonic === VALID_SEED_PHRASE) {
12+
console.log("Valid test phrase detected");
13+
return true;
14+
}
15+
const words = mnemonic.split(" ");
16+
const isValid = words.length === 12 && words.every(word => word.length > 0);
17+
console.log(`Validation result for "${mnemonic}": ${isValid}`);
18+
return isValid;
19+
}
20+
export function mnemonicToEntropy(mnemonic) {
21+
console.log("Mock mnemonicToEntropy called with:", mnemonic);
22+
if (!validateMnemonic(mnemonic)) {
23+
throw new Error("Invalid mnemonic");
24+
}
25+
// For testing, return a fixed valid entropy for our test seed phrase
26+
if (mnemonic === VALID_SEED_PHRASE) {
27+
console.log("Returning test entropy");
28+
return VALID_ENTROPY;
29+
}
30+
// For other valid phrases, generate a deterministic entropy
31+
console.log("Generating deterministic entropy");
32+
const words = mnemonic.split(" ");
33+
const entropy = new Uint8Array(16); // 16 bytes = 128 bits
34+
for (let i = 0; i < 16; i++) {
35+
entropy[i] = (i + 1) % 256; // Simple deterministic pattern
36+
}
37+
return bytesToHex(entropy);
38+
}

dist/__tests__/index.test.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

0 commit comments

Comments
 (0)