Added BIP32Derive, which uses bip32 from bitcoinjs. Modified a few more operations. Code compiles with 20.3.0

This commit is contained in:
David C Goldenberg 2024-08-19 20:37:12 -04:00
parent 810c94803d
commit f474ffaf72
17 changed files with 764 additions and 170 deletions

View file

@ -129,6 +129,7 @@ import "./tests/DecryptKeyStoreFile.mjs";
import "./tests/WIFToPrivateKey.mjs";
import "./tests/SeedphraseToSeed.mjs";
import "./tests/DeserializeExtendedKey.mjs";
import "./tests/PublicKeyToETHStyleAddress.mjs";
import "./tests/GetAllCasings.mjs";
import "./tests/SIGABA.mjs";
import "./tests/ELFInfo.mjs";

View file

@ -34,8 +34,8 @@ TestRegister.addTests([
"args": [false]
},
{
"op": "Public Key To Cryptocurrency Address",
"args": ["Ethereum", "P2PKH (V1 BTC Addresses)"]
"op": "Public Key To ETH Style Address",
"args": []
}
]

View file

@ -50,7 +50,7 @@ TestRegister.addTests([
{
name: "Private EC Key to Public (Wrong Length)",
input: "5E2A8FDE9F861056607208F512287CFBD634E124044EE23EBF7289E8E7B3822E08",
expectedOutput: "Must pass a hex string of length 64, or a byte string of length 32. Got length 66",
expectedOutput: "Error with the input as private key. Error is:\n\tInvalid length. We want either 32 or 64 but we got: 66",
recipeConfig: [
{
"op": "Private EC Key to Public Key",
@ -61,7 +61,7 @@ TestRegister.addTests([
{
name: "Private EC Key to Public (From Bytes Uncompressed Wrong Length)",
input: "5E2A8FDE9F861056607208F512287CFBD634E124044EE23EBF7289E8E7B3822E08",
expectedOutput: "Must pass a hex string of length 64, or a byte string of length 32. Got length 33",
expectedOutput: "Error with the input as private key. Error is:\n\tInvalid length. We want either 32 or 64 but we got: 33",
recipeConfig: [
{
"op": "From Hex",

View file

@ -61,7 +61,7 @@ TestRegister.addTests([
{
name: "Private Key To WIF (BTC, Compressed, Wrong Number of Bytes)",
input: "5E2A8FDE9F861056607208F512287CFBD634E124044EE23EBF7289E8E7B3822E08",
expectedOutput: "Must pass a hex string of length 64, or a byte string of length 32. Got length: 66",
expectedOutput: "Error parsing private key. Error is:\n\tInvalid length. We want either 32 or 64 but we got: 66",
recipeConfig: [
{
"op": "To WIF Format",
@ -72,7 +72,7 @@ TestRegister.addTests([
{
name: "Private Key To WIF (BTC, Compressed, Wrong Number of Bytes)",
input: "5E2A8FDE9F861056607208F512287CFBD634E124044EE23EBF7289E8E7B3822E08",
expectedOutput: "Must pass a hex string of length 64, or a byte string of length 32. Got length: 33",
expectedOutput: "Error parsing private key. Error is:\n\tInvalid length. We want either 32 or 64 but we got: 33",
recipeConfig: [
{
"op": "From Hex",

View file

@ -0,0 +1,110 @@
/**
* Public Key to ETH Style Address Cryptocurrency Address tests.
*
* @author dgoldenberg [virtualcurrency@mitre.org]
* @copyright MITRE 2023
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "Public Key To ETH Style Address",
input: "04d26bcecd763bdf6bdb89ba929d2485429fbda73bae723d525ef55554ef45350582085bd24055079f6deebad5b6af612c14587c6862391d330484afe750fbf144",
expectedOutput: "0x63e8b85679d29235791a0f558d6485c7ed51c9e6",
recipeConfig: [
{
"op": "Public Key To ETH Style Address",
"args": []
},
],
},
{
name: "Public Key To ETH Style Address 2",
input: "047d3e5107b46421c3ddf7292fcbe1f5805952279926c325d119f6ddfed1e5e7ea9a9f5dceadc57b897cb286479450b66a6422f8f270bcd2a61ab4eea800911956",
expectedOutput: "0x099f75d5bc069026531394d5c6d6c37a41158d31",
recipeConfig: [
{
"op": "Public Key To ETH Style Address",
"args": []
},
],
},
{
name: "Public Key to ETH Style Address: Compressed Key",
input: "027d3e5107b46421c3ddf7292fcbe1f5805952279926c325d119f6ddfed1e5e7ea",
expectedOutput: "0x099f75d5bc069026531394d5c6d6c37a41158d31",
recipeConfig: [
{
"op": "Public Key To ETH Style Address",
"args": []
},
],
},
{
name: "Public Key to ETH Style Address: Compressed Key 2",
input: "039d491d3f5a2a79b422b76b8115b175b38e42c6103b1a84c88fb6221fe9072bbe",
expectedOutput: "0x345029d286159d516ca1169edf0a80ff6c855ac0",
recipeConfig: [
{
"op": "Public Key To ETH Style Address",
"args": [],
},
],
},
{
name: "Public Key to ETH Style Address: Compressed Key (From Hex)",
input: "027d3e5107b46421c3ddf7292fcbe1f5805952279926c325d119f6ddfed1e5e7ea",
expectedOutput: "0x099f75d5bc069026531394d5c6d6c37a41158d31",
recipeConfig: [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "Public Key To ETH Style Address",
"args": []
},
],
},
{
name: "Public Key to ETH Style Address: Compressed Key 2 (From Hex)",
input: "039d491d3f5a2a79b422b76b8115b175b38e42c6103b1a84c88fb6221fe9072bbe",
expectedOutput: "0x345029d286159d516ca1169edf0a80ff6c855ac0",
recipeConfig: [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "Public Key To ETH Style Address",
"args": [],
},
],
},
{
name: "Public Key To ETH Style Address (From Hex)",
input: "04d26bcecd763bdf6bdb89ba929d2485429fbda73bae723d525ef55554ef45350582085bd24055079f6deebad5b6af612c14587c6862391d330484afe750fbf144",
expectedOutput: "0x63e8b85679d29235791a0f558d6485c7ed51c9e6",
recipeConfig: [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "Public Key To ETH Style Address",
"args": []
},
],
},
]);

View file

@ -32,6 +32,17 @@ TestRegister.addTests([
},
],
},
{
name: "Public Key To Address: P2PKH LTC",
input: "037b39f764a10f31bfd47038738ca27bffeefce1fe4ccbfb9343fcb69d9363b27b",
expectedOutput: "LPTR2TBuF8vbwWaJdNeCAQemW4SC7q7zJP",
recipeConfig: [
{
"op": "Public Key To Cryptocurrency Address",
"args": ["LTC", "P2PKH (V1 BTC Addresses)"]
},
],
},
{
name: "Public Key To Address: P2PKH (Long)",
input: "04219A19E157B5FEDDF7EBDD3C7A58D7AB4F6565E84226691B6A5F80BBCE8E0100B49D6AB503CA4B701626E941EB8D2460F154992D7AD4EC671CF1CFB8C1DE8164",
@ -50,7 +61,7 @@ TestRegister.addTests([
recipeConfig: [
{
"op": "Public Key To Cryptocurrency Address",
"args": ["BTC", "P2SH-P2PWPKH (Segwit Compatible)"]
"args": ["BTC", "P2SH-P2PWPKH (Segwit Compatible V3 Addresses)"]
},
],
},
@ -61,7 +72,18 @@ TestRegister.addTests([
recipeConfig: [
{
"op": "Public Key To Cryptocurrency Address",
"args": ["BTC", "P2SH-P2PWPKH (Segwit Compatible)"]
"args": ["BTC", "P2SH-P2PWPKH (Segwit Compatible V3 Addresses)"]
},
],
},
{
name: "Public Key To Address: P2SH-P2WPKH LTC",
input: "02f442a169ca36702bbcbb268319295bece8fe1cbc6ca095b2669d13ef56c759de",
expectedOutput: "MMwYiJmkxDKqiP2WWAHMMgkeRt2nLxGqih",
recipeConfig: [
{
"op": "Public Key To Cryptocurrency Address",
"args": ["LTC", "P2SH-P2PWPKH (Segwit Compatible V3 Addresses)"]
},
],
},
@ -72,7 +94,7 @@ TestRegister.addTests([
recipeConfig: [
{
"op": "Public Key To Cryptocurrency Address",
"args": ["BTC", "Segwit (P2WPKH)"]
"args": ["BTC", "Segwit (P2WPKH bc1 Addresses)"]
},
],
},
@ -83,21 +105,20 @@ TestRegister.addTests([
recipeConfig: [
{
"op": "Public Key To Cryptocurrency Address",
"args": ["BTC", "Segwit (P2WPKH)"]
"args": ["BTC", "Segwit (P2WPKH bc1 Addresses)"]
},
],
},
{
name: "Public Key To Address: (ETH)",
input: "04d26bcecd763bdf6bdb89ba929d2485429fbda73bae723d525ef55554ef45350582085bd24055079f6deebad5b6af612c14587c6862391d330484afe750fbf144",
expectedOutput: "0x63e8b85679d29235791a0f558d6485c7ed51c9e6",
name: "Public Key To Address: P2WPKH LTC",
input: "026a532c31184b94edf540ad60c3cc208342be4f51cc764a373a420731dd198a59",
expectedOutput: "ltc1qj587punda8h0r4m83k794xseqlnl3az4ktu2zp",
recipeConfig: [
{
"op": "Public Key To Cryptocurrency Address",
"args": ["Ethereum", "Segwit (P2WPKH)"]
"args": ["LTC", "Segwit (P2WPKH bc1 Addresses)"]
},
],
},
{
name: "Public Key To Address: (Testnet)",
@ -114,29 +135,29 @@ TestRegister.addTests([
{
name: "Public Key To Address: P2WPKH (Wrong Length)",
input: "03bc32bdc5dc96c9fb56e2481fefd321ebe9e17a807bbb337dea1df5e68b1f075642",
expectedOutput: "Input is wrong length. Should be either 33 or 65 bytes, but is: 34",
expectedOutput: "Invalid length. We want either 33, 65 (if bytes) or 66, 130 (if hex) but we got: 68",
recipeConfig: [
{
"op": "Public Key To Cryptocurrency Address",
"args": ["BTC", "Segwit (P2WPKH)"]
"args": ["BTC", "Segwit (P2WPKH bc1 Addresses)"]
},
],
},
{
name: "Public Key To Address: P2WPKH (Wrong Start)",
input: "05bc32bdc5dc96c9fb56e2481fefd321ebe9e17a807bbb337dea1df5e68b1f0756",
expectedOutput: "Input is 33 bytes, but begins with invalid byte: 05",
expectedOutput: "We have a valid hex string, of reasonable length, (66) but doesn't start with the right value. Correct values are 02, or 03 but we have: 05",
recipeConfig: [
{
"op": "Public Key To Cryptocurrency Address",
"args": ["BTC", "Segwit (P2WPKH)"]
"args": ["BTC", "Segwit (P2WPKH bc1 Addresses)"]
},
],
},
{
name: "Public Key To Address: P2PKH (Long With Error)",
input: "06219A19E157B5FEDDF7EBDD3C7A58D7AB4F6565E84226691B6A5F80BBCE8E0100B49D6AB503CA4B701626E941EB8D2460F154992D7AD4EC671CF1CFB8C1DE8164",
expectedOutput: "Input is 65 bytes, but begins with invalid byte: 06",
expectedOutput: "We have a valid hex string of reasonable length, (130) but doesn't start with the right value. Correct values are 04 but we have: 06",
recipeConfig: [
{
"op": "Public Key To Cryptocurrency Address",
@ -159,16 +180,4 @@ TestRegister.addTests([
}
],
},
{
name: "Public Key To Address: (ETH Compressed Key)",
input: "03ebf60a619da2fbc6239089ca0a93878ea53baa3d22188cacad4033b103237ae9",
expectedOutput: "Ethereum addresses require uncompressed public keys.",
recipeConfig: [
{
"op": "Public Key To Cryptocurrency Address",
"args": ["Ethereum", "Segwit (P2WPKH)"]
},
],
}
]);

View file

@ -21,6 +21,21 @@ TestRegister.addTests([
}
],
},
{
name: "Seed To Master Private Key (xprv) From Hex",
input: "c766f48d3729a16249b5d0171c678d458d31454b2bb7791b61169b5541a130719714ebd41f22a2515246d013e9a4e978aee48dd5140b73a540108d58008c4aa9",
expectedOutput: "xprv9s21ZrQH143K2nwujwREGif1wyBwt5Jh9BdFVSgSeYdrUp1qPxKsHrmnpJ8xKpKPDvXJMmBRpsZ3X64MeafyURs8Xoj53kGu7hb48Yg7unj",
recipeConfig: [
{
"op": "From Hex",
"args": ["Auto"]
},
{
"op": "Seed To Master Key",
"args": ["xprv"]
}
],
},
{
name: "Seed To Master Private Key (tprv)",
input: "c766f48d3729a16249b5d0171c678d458d31454b2bb7791b61169b5541a130719714ebd41f22a2515246d013e9a4e978aee48dd5140b73a540108d58008c4aa9",