Resolve "Move Hasher and Encryptor to Primitives"
This commit is contained in:
@@ -161,6 +161,14 @@ export default withMermaid({
|
||||
link: '/tools/primitives#block-header',
|
||||
},
|
||||
{ text: 'Bytes', link: '/tools/primitives#bytes' },
|
||||
{
|
||||
text: 'Encrypter',
|
||||
link: '/tools/primitives#encrypter',
|
||||
},
|
||||
{
|
||||
text: 'Hasher',
|
||||
link: '/tools/primitives#hasher',
|
||||
},
|
||||
{
|
||||
text: 'HD Private Node',
|
||||
link: '/tools/primitives#hd-private-node',
|
||||
@@ -210,7 +218,6 @@ export default withMermaid({
|
||||
},
|
||||
],
|
||||
},
|
||||
*/
|
||||
{
|
||||
text: 'Utils',
|
||||
link: '/tools/stack/utils',
|
||||
@@ -222,6 +229,7 @@ export default withMermaid({
|
||||
{ text: 'Hasher', link: '/tools/stack/utils#hasher' },
|
||||
],
|
||||
},
|
||||
*/
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -4,8 +4,8 @@ import {
|
||||
Bytes,
|
||||
encodeExtendedJson,
|
||||
decodeExtendedJson,
|
||||
// Encrypter,
|
||||
// Hasher,
|
||||
Encrypter,
|
||||
Hasher,
|
||||
HDPrivateNode,
|
||||
HDPublicNode,
|
||||
Mnemonic,
|
||||
@@ -204,6 +204,78 @@ export const bytes = {
|
||||
],
|
||||
};
|
||||
|
||||
export const encrypter = {
|
||||
from: [
|
||||
{
|
||||
label: 'From Passphrase',
|
||||
inputs: ['Passphrase'],
|
||||
models: [''],
|
||||
callback: (args: [string]) => Encrypter.fromPassphrase(...args),
|
||||
extendedInput: true,
|
||||
},
|
||||
],
|
||||
to: [],
|
||||
methods: [
|
||||
{
|
||||
label: 'Encrypt',
|
||||
inputs: ['UTF8'],
|
||||
models: ['Your text here'],
|
||||
callback: async (encrypter: Encrypter, args: [string]) =>
|
||||
Bytes.fromBytes(await encrypter.encrypt(...args)).toHex(),
|
||||
},
|
||||
{
|
||||
label: 'Decrypt',
|
||||
inputs: ['Hex'],
|
||||
models: ['Encrypted Data (hex)'],
|
||||
callback: async (encrypter: Encrypter, args: [string]) =>
|
||||
Bytes.fromBytes(
|
||||
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(),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const hdPrivateNode = {
|
||||
from: [
|
||||
{
|
||||
|
||||
@@ -10,6 +10,8 @@ import {
|
||||
address,
|
||||
blockHeader,
|
||||
bytes,
|
||||
encrypter,
|
||||
hasher,
|
||||
hdPrivateNode,
|
||||
hdPublicNode,
|
||||
mnemonic,
|
||||
@@ -65,6 +67,31 @@ Note that these are still unstable and will change in future.
|
||||
/>
|
||||
</div>
|
||||
|
||||
## Encrypter
|
||||
|
||||
<div class="tool">
|
||||
<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="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>
|
||||
|
||||
## HD Private Node
|
||||
|
||||
<div class="tool">
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
import { Bytes } from '@xocash/primitives';
|
||||
import { Encrypter, Hasher } from '@xocash/stack';
|
||||
|
||||
export const encrypter = {
|
||||
from: [
|
||||
{
|
||||
label: 'From Passphrase',
|
||||
inputs: ['Passphrase'],
|
||||
models: [''],
|
||||
callback: (args: [string]) => Encrypter.fromPassphrase(...args),
|
||||
extendedInput: true,
|
||||
},
|
||||
],
|
||||
to: [],
|
||||
methods: [
|
||||
{
|
||||
label: 'Encrypt',
|
||||
inputs: ['UTF8'],
|
||||
models: ['Your text here'],
|
||||
callback: async (encrypter: Encrypter, args: [string]) =>
|
||||
Bytes.fromBytes(await encrypter.encrypt(...args)).toHex(),
|
||||
},
|
||||
{
|
||||
label: 'Decrypt',
|
||||
inputs: ['Hex'],
|
||||
models: ['Encrypted Data (hex)'],
|
||||
callback: async (encrypter: Encrypter, args: [string]) =>
|
||||
Bytes.fromBytes(
|
||||
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(),
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -1,42 +0,0 @@
|
||||
---
|
||||
aside: false
|
||||
---
|
||||
|
||||
<script lang="ts" setup>
|
||||
import PrimitiveToolVue, { type FromFunction, type ToFunction } from '@theme/components/PrimitiveTool.vue'
|
||||
|
||||
// Import our tool functions
|
||||
import {
|
||||
encrypter,
|
||||
hasher,
|
||||
} from './utils-functions.ts'
|
||||
</script>
|
||||
|
||||
<!-- Resume Markdown parsing -->
|
||||
|
||||
# Utils
|
||||
|
||||
## Encrypter
|
||||
|
||||
<div class="tool">
|
||||
<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="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>
|
||||
@@ -1,7 +1,9 @@
|
||||
export * from './address.js';
|
||||
export * from './block-header.js';
|
||||
export * from './bytes.js';
|
||||
export * from './encrypter.js';
|
||||
export * from './ext-json.js';
|
||||
export * from './hasher.js';
|
||||
export * from './hd-private-node.js';
|
||||
export * from './hd-public-node.js';
|
||||
export * from './mnemonic.js';
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
|
||||
import { Encrypter } from '~/src/utils/encrypter';
|
||||
import { Encrypter } from '../src/encrypter';
|
||||
import { binToUtf8, utf8ToBin } from '@bitauth/libauth';
|
||||
|
||||
describe('Encrypter', () => {
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Encrypter, EventEmitter, InverseBloomFilter } from '../utils';
|
||||
|
||||
import { EventEmitter, InverseBloomFilter } from '../utils';
|
||||
import { Encrypter } from '@xocash/primitives';
|
||||
export type StorageOpts = {
|
||||
syncInMemory?: boolean;
|
||||
encryption?: Encrypter;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { BaseStorage, BaseStore, StorageOpts } from './base-store.js';
|
||||
import { StoreInMemorySynced } from './store-inmemory-synced.js';
|
||||
|
||||
import { Encrypter } from '../utils';
|
||||
import { Encrypter } from '@xocash/primitives';
|
||||
|
||||
// TODO: Only use pack/unpack on encrypted content.
|
||||
// Unsure why you were doing it on non-encrypted content (as it's not needed for IDB).
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { BaseStore } from './base-store.js';
|
||||
import { Encrypter, SSEClient } from '../utils';
|
||||
import { SSEClient } from '../utils';
|
||||
import {
|
||||
Bytes,
|
||||
Encrypter,
|
||||
PrivateKey,
|
||||
PublicKey,
|
||||
decodeExtendedJson,
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
export * from './encrypter.js';
|
||||
export * from './event-emitter.js';
|
||||
export * from './ext-error.js';
|
||||
export * from './hasher.js';
|
||||
export * from './inverse-bloom-filter.js';
|
||||
export * from './memoizer.js';
|
||||
export * from './misc.js';
|
||||
|
||||
Reference in New Issue
Block a user