Amend Primitives/Tooling
This commit is contained in:
@@ -129,7 +129,6 @@ export default defineConfig({
|
||||
link: '/tools/primitives#block-header',
|
||||
},
|
||||
{ text: 'Bytes', link: '/tools/primitives#bytes' },
|
||||
{ text: 'Hasher', link: '/tools/primitives#hasher' },
|
||||
{
|
||||
text: 'HD Private Node',
|
||||
link: '/tools/primitives#hd-private-node',
|
||||
@@ -164,18 +163,35 @@ export default defineConfig({
|
||||
},
|
||||
],
|
||||
},
|
||||
/*
|
||||
{
|
||||
text: 'Stack',
|
||||
collapsed: false,
|
||||
items: [
|
||||
/*
|
||||
{
|
||||
text: 'Blockchain',
|
||||
items: [{ text: 'Blockchain Electrum' }],
|
||||
link: '/tools/stack/blockchain',
|
||||
items: [
|
||||
{
|
||||
text: 'Electrum',
|
||||
link: '/tools/stack/blockchain#encryption',
|
||||
},
|
||||
],
|
||||
},
|
||||
*/
|
||||
{
|
||||
text: 'Utils',
|
||||
link: '/tools/stack/utils',
|
||||
items: [
|
||||
{
|
||||
text: 'Encrypter',
|
||||
link: '/tools/stack/utils#encrypter',
|
||||
},
|
||||
{ text: 'Hasher', link: '/tools/stack/utils#hasher' },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
*/
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -30,6 +30,10 @@ body {
|
||||
.vp-doc h4 {
|
||||
font-size: 14px;
|
||||
opacity: 0.75;
|
||||
color: var(--primary);
|
||||
padding-top: 3em;
|
||||
border-top: 1px solid var(--vp-c-text-1);
|
||||
margin-top: 3em;
|
||||
}
|
||||
|
||||
.VPSidebarItem .text {
|
||||
|
||||
@@ -4,7 +4,8 @@ import {
|
||||
Bytes,
|
||||
encodeExtendedJson,
|
||||
decodeExtendedJson,
|
||||
Hasher,
|
||||
// Encrypter,
|
||||
// Hasher,
|
||||
HDPrivateNode,
|
||||
HDPublicNode,
|
||||
Mnemonic,
|
||||
@@ -116,10 +117,10 @@ export const address = {
|
||||
export const blockHeader = {
|
||||
from: [
|
||||
{
|
||||
label: 'From Hex',
|
||||
inputs: ['UTF-8'],
|
||||
label: 'From',
|
||||
inputs: ['Hex'],
|
||||
models: [''],
|
||||
callback: (args: [string]) => BlockHeader.fromHex(...args),
|
||||
callback: (args: [string]) => BlockHeader.from(...args),
|
||||
},
|
||||
],
|
||||
to: [
|
||||
@@ -193,67 +194,30 @@ export const bytes = {
|
||||
],
|
||||
};
|
||||
|
||||
export const hasher = {
|
||||
from: [
|
||||
{
|
||||
label: 'From Hex',
|
||||
inputs: ['Hex'],
|
||||
models: [''],
|
||||
callback: (args: [string]) => Hasher.fromHex(...args),
|
||||
},
|
||||
{
|
||||
label: 'From Base64',
|
||||
inputs: ['Base64'],
|
||||
models: [''],
|
||||
callback: (args: [string]) => Hasher.fromBase64(...args),
|
||||
},
|
||||
{
|
||||
label: 'From UTF-8',
|
||||
inputs: ['UTF-8'],
|
||||
models: [''],
|
||||
callback: (args: [string]) => Hasher.fromUTF8(...args),
|
||||
},
|
||||
],
|
||||
to: [
|
||||
{
|
||||
label: 'To Sha256 Hex',
|
||||
callback: (hasher: Hasher) => hasher.toSHA256Hex(),
|
||||
},
|
||||
{
|
||||
label: 'To RipeMD160 Hex',
|
||||
callback: (hasher: Hasher) => hasher.toRIPEMD160Hex(),
|
||||
},
|
||||
{
|
||||
label: 'To Hash160 Hex',
|
||||
callback: (hasher: Hasher) => hasher.toHash160Hex(),
|
||||
},
|
||||
{
|
||||
label: 'To Hash256 Hex',
|
||||
callback: (hasher: Hasher) => hasher.toHash256Hex(),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const hdPrivateNode = {
|
||||
from: [
|
||||
{
|
||||
label: 'Generate Random',
|
||||
inputs: ['Derivation Path'],
|
||||
models: ["m/44'/145'/0'/0/1"],
|
||||
callback: () => HDPrivateNode.generateRandom(),
|
||||
},
|
||||
{
|
||||
label: 'From Mnemonic',
|
||||
inputs: ['Mnemonic', 'Derivation Path'],
|
||||
models: ['', "m/44'/145'/0'/0/1"],
|
||||
label: 'From Mnemonic Phrase',
|
||||
inputs: ['Mnemonic'],
|
||||
models: [''],
|
||||
callback: (args: [string]) => HDPrivateNode.fromMnemonic(...args),
|
||||
},
|
||||
{
|
||||
label: 'From XPriv Key',
|
||||
inputs: ['XPriv Key', 'Derivation Path'],
|
||||
models: ['', "m/44'/145'/0'/0/1"],
|
||||
inputs: ['XPriv Key'],
|
||||
models: [''],
|
||||
callback: (args: [string]) => HDPrivateNode.fromXPriv(...args),
|
||||
},
|
||||
{
|
||||
label: 'From Seed',
|
||||
inputs: ['Seed (Hex)'],
|
||||
models: [''],
|
||||
callback: (args: [string]) => HDPrivateNode.fromSeed(...args),
|
||||
},
|
||||
{
|
||||
label: 'From Raw',
|
||||
inputs: ['Raw (LibAuth Format/ExtJSON Encoded)'],
|
||||
@@ -283,6 +247,18 @@ export const hdPrivateNode = {
|
||||
hdPrivateNode.deriveHDPublicNode().toXPub(),
|
||||
},
|
||||
],
|
||||
methods: [
|
||||
{
|
||||
label: 'Derive Path',
|
||||
inputs: ['BIP32 Path'],
|
||||
models: ["m/44'/145'/0'/0/0"],
|
||||
callback: (hdPrivateNode: HDPrivateNode, args: [string]) =>
|
||||
hdPrivateNode
|
||||
.derivePath(...args)
|
||||
.toPrivateKey()
|
||||
.toWif(),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const hdPublicNode = {
|
||||
@@ -317,30 +293,50 @@ export const hdPublicNode = {
|
||||
encodeExtendedJson(hdPublicNode.toRaw(), 2),
|
||||
},
|
||||
],
|
||||
methods: [
|
||||
{
|
||||
label: 'Derive Path',
|
||||
inputs: ['BIP32 Public Key Path'],
|
||||
models: ['M/0/0'],
|
||||
callback: (hdPublicNode: HDPublicNode, args: [string]) =>
|
||||
hdPublicNode
|
||||
.derivePath(...args)
|
||||
.toPublicKey()
|
||||
.deriveAddress()
|
||||
.toCashAddr(),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const mnemonic = {
|
||||
from: [
|
||||
{
|
||||
label: 'Generate Random',
|
||||
callback: () => Mnemonic.generateRandom(),
|
||||
inputs: ['Passphrase (Optional)'],
|
||||
models: [undefined],
|
||||
callback: (args: [string?]) => Mnemonic.generateRandom(...args),
|
||||
},
|
||||
{
|
||||
label: 'From String',
|
||||
inputs: ['String'],
|
||||
label: 'From Phrase',
|
||||
inputs: ['Mnemonic Phrase'],
|
||||
models: [''],
|
||||
callback: (args: [string]) => Mnemonic.fromString(...args),
|
||||
callback: (args: [string]) => Mnemonic.fromPhrase(...args),
|
||||
extendedInput: true,
|
||||
},
|
||||
],
|
||||
to: [
|
||||
{
|
||||
label: 'To String (without passphrase)',
|
||||
callback: (mnemonic: Mnemonic) => mnemonic.toString(false),
|
||||
label: 'To Seed',
|
||||
callback: (mnemonic: Mnemonic) =>
|
||||
Bytes.fromBytes(mnemonic.toSeed()).toHex(),
|
||||
},
|
||||
{
|
||||
label: 'To String (with passphrase)',
|
||||
callback: (mnemonic: Mnemonic) => mnemonic.toString(true),
|
||||
label: 'To Phrase (without passphrase)',
|
||||
callback: (mnemonic: Mnemonic) => mnemonic.toPhrase(false),
|
||||
},
|
||||
{
|
||||
label: 'To Phrase (with passphrase)',
|
||||
callback: (mnemonic: Mnemonic) => mnemonic.toPhrase(true),
|
||||
},
|
||||
{
|
||||
label: 'Words',
|
||||
@@ -361,16 +357,10 @@ export const privateKey = {
|
||||
callback: () => PrivateKey.generateRandom(),
|
||||
},
|
||||
{
|
||||
label: 'From Hex',
|
||||
inputs: ['Hex'],
|
||||
label: 'From Hex or WIF',
|
||||
inputs: ['Hex or WIF'],
|
||||
models: [''],
|
||||
callback: (args: [string]) => PrivateKey.fromHex(...args),
|
||||
},
|
||||
{
|
||||
label: 'From WIF',
|
||||
inputs: ['WIF'],
|
||||
models: [''],
|
||||
callback: (args: [string]) => PrivateKey.fromWIF(...args),
|
||||
callback: (args: [string]) => PrivateKey.from(...args),
|
||||
},
|
||||
],
|
||||
to: [
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
address,
|
||||
blockHeader,
|
||||
bytes,
|
||||
hasher,
|
||||
hdPrivateNode,
|
||||
hdPublicNode,
|
||||
mnemonic,
|
||||
@@ -58,18 +57,6 @@ import {
|
||||
/>
|
||||
</div>
|
||||
|
||||
## Hasher
|
||||
|
||||
<div class="tool">
|
||||
<p>A utility tool for computing various cryptographic hashes commonly used in Bitcoin Cash.</p>
|
||||
|
||||
<PrimitiveToolVue
|
||||
:fromFunctions="hasher.from"
|
||||
:toFunctions="hasher.to"
|
||||
/>
|
||||
|
||||
</div>
|
||||
|
||||
## HD Private Node
|
||||
|
||||
<div class="tool">
|
||||
@@ -78,6 +65,7 @@ import {
|
||||
<PrimitiveToolVue
|
||||
:fromFunctions="hdPrivateNode.from"
|
||||
:toFunctions="hdPrivateNode.to"
|
||||
:methods="hdPrivateNode.methods"
|
||||
/>
|
||||
|
||||
</div>
|
||||
@@ -90,6 +78,7 @@ import {
|
||||
<PrimitiveToolVue
|
||||
:fromFunctions="hdPublicNode.from"
|
||||
:toFunctions="hdPublicNode.to"
|
||||
:methods="hdPublicNode.methods"
|
||||
/>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import { Bytes } from '@xocash/primitives';
|
||||
import { Encrypter, Hasher } from '@xocash/stack';
|
||||
|
||||
import { Encryption } from '@xocash/stack';
|
||||
|
||||
export const encryption = {
|
||||
export const encrypter = {
|
||||
from: [
|
||||
{
|
||||
label: 'From Passphrase',
|
||||
inputs: ['Passphrase'],
|
||||
models: [''],
|
||||
callback: (args: [string]) => Encryption.fromPassphrase(...args),
|
||||
callback: (args: [string]) => Encrypter.fromPassphrase(...args),
|
||||
extendedInput: true,
|
||||
},
|
||||
],
|
||||
@@ -18,17 +17,58 @@ export const encryption = {
|
||||
label: 'Encrypt',
|
||||
inputs: ['UTF8'],
|
||||
models: ['Your text here'],
|
||||
callback: async (encryption: Encryption, args: [string]) =>
|
||||
Bytes.fromBytes(await encryption.encrypt(...args)).toHex(),
|
||||
callback: async (encrypter: Encrypter, args: [string]) =>
|
||||
Bytes.fromBytes(await encrypter.encrypt(...args)).toHex(),
|
||||
},
|
||||
{
|
||||
label: 'Decrypt',
|
||||
inputs: ['Hex'],
|
||||
models: ['Encrypted Data (hex)'],
|
||||
callback: async (encryption: Encryption, args: [string]) =>
|
||||
callback: async (encrypter: Encrypter, args: [string]) =>
|
||||
Bytes.fromBytes(
|
||||
await encryption.decrypt(Bytes.fromHex(...args).toBytes()),
|
||||
await encrypter.decrypt(Bytes.fromHex(...args).toBytes()),
|
||||
).toUtf8(),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const hasher = {
|
||||
from: [
|
||||
{
|
||||
label: 'From Hex',
|
||||
inputs: ['Hex'],
|
||||
models: [''],
|
||||
callback: (args: [string]) => Hasher.fromHex(...args),
|
||||
},
|
||||
{
|
||||
label: 'From Base64',
|
||||
inputs: ['Base64'],
|
||||
models: [''],
|
||||
callback: (args: [string]) => Hasher.fromBase64(...args),
|
||||
},
|
||||
{
|
||||
label: 'From UTF-8',
|
||||
inputs: ['UTF-8'],
|
||||
models: [''],
|
||||
callback: (args: [string]) => Hasher.fromUTF8(...args),
|
||||
},
|
||||
],
|
||||
to: [
|
||||
{
|
||||
label: 'To Sha256 Hex',
|
||||
callback: (hasher: Hasher) => hasher.toSHA256Hex(),
|
||||
},
|
||||
{
|
||||
label: 'To RipeMD160 Hex',
|
||||
callback: (hasher: Hasher) => hasher.toRIPEMD160Hex(),
|
||||
},
|
||||
{
|
||||
label: 'To Hash160 Hex',
|
||||
callback: (hasher: Hasher) => hasher.toHash160Hex(),
|
||||
},
|
||||
{
|
||||
label: 'To Hash256 Hex',
|
||||
callback: (hasher: Hasher) => hasher.toHash256Hex(),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -3,7 +3,8 @@ import PrimitiveToolVue, { type FromFunction, type ToFunction } from '@theme/com
|
||||
|
||||
// Import our tool functions
|
||||
import {
|
||||
encryption
|
||||
encrypter,
|
||||
hasher,
|
||||
} from './utils-functions.ts'
|
||||
</script>
|
||||
|
||||
@@ -11,15 +12,27 @@ import {
|
||||
|
||||
# Utils
|
||||
|
||||
## Encryption
|
||||
## Encrypter
|
||||
|
||||
<div class="tool">
|
||||
<p>A Utility tool for converting between different address formats.</p>
|
||||
<p>A Utility tool for encrypting data using AES-GCM.</p>
|
||||
<p>Additional parameters (Salt, Key Length, IV, etc) are available via the API.</p>
|
||||
|
||||
<PrimitiveToolVue
|
||||
:fromFunctions="encryption.from"
|
||||
:toFunctions="encryption.to"
|
||||
:methods="encryption.methods"
|
||||
:fromFunctions="encrypter.from"
|
||||
:toFunctions="encrypter.to"
|
||||
:methods="encrypter.methods"
|
||||
/>
|
||||
</div>
|
||||
|
||||
## Hasher
|
||||
|
||||
<div class="tool">
|
||||
<p>A utility tool for computing various cryptographic hashes commonly used in Bitcoin Cash.</p>
|
||||
|
||||
<PrimitiveToolVue
|
||||
:fromFunctions="hasher.from"
|
||||
:toFunctions="hasher.to"
|
||||
/>
|
||||
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user