Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/js-evo-sdk/src/dpns/facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ export class DpnsFacade {
this.sdk = sdk;
}

convertToHomographSafe(input: string): string {
async convertToHomographSafe(input: string): Promise<string> {
await wasm.ensureInitialized();
return wasm.WasmSdk.dpnsConvertToHomographSafe(input);
}

isValidUsername(label: string): boolean {
async isValidUsername(label: string): Promise<boolean> {
await wasm.ensureInitialized();
return wasm.WasmSdk.dpnsIsValidUsername(label);
}

isContestedUsername(label: string): boolean {
async isContestedUsername(label: string): Promise<boolean> {
await wasm.ensureInitialized();
return wasm.WasmSdk.dpnsIsContestedUsername(label);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/js-evo-sdk/src/tokens/facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export class TokensFacade {
this.sdk = sdk;
}

calculateId(contractId: string, tokenPosition: number): string {
async calculateId(contractId: string, tokenPosition: number): Promise<string> {
await wasm.ensureInitialized();
return wasm.WasmSdk.calculateTokenIdFromContract(contractId, tokenPosition);
}

Expand Down
66 changes: 44 additions & 22 deletions packages/js-evo-sdk/src/wallet/functions.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
import * as wasm from '../wasm.js';

export namespace wallet {
export function generateMnemonic(wordCount?: number, languageCode?: string): string {
export async function generateMnemonic(wordCount?: number, languageCode?: string): Promise<string> {
await wasm.ensureInitialized();
return wasm.WasmSdk.generateMnemonic(wordCount ?? null, languageCode ?? null);
}

export function validateMnemonic(mnemonic: string, languageCode?: string): boolean {
export async function validateMnemonic(mnemonic: string, languageCode?: string): Promise<boolean> {
await wasm.ensureInitialized();
return wasm.WasmSdk.validateMnemonic(mnemonic, languageCode ?? null);
}

export function mnemonicToSeed(mnemonic: string, passphrase?: string): Uint8Array {
export async function mnemonicToSeed(mnemonic: string, passphrase?: string): Promise<Uint8Array> {
await wasm.ensureInitialized();
return wasm.WasmSdk.mnemonicToSeed(mnemonic, passphrase ?? null);
}

export function deriveKeyFromSeedPhrase(mnemonic: string, passphrase: string | null | undefined, network: string): any {
export async function deriveKeyFromSeedPhrase(mnemonic: string, passphrase: string | null | undefined, network: string): Promise<any> {
await wasm.ensureInitialized();
return wasm.WasmSdk.deriveKeyFromSeedPhrase(mnemonic, passphrase ?? null, network);
}

export function deriveKeyFromSeedWithPath(mnemonic: string, passphrase: string | null | undefined, path: string, network: string): any {
export async function deriveKeyFromSeedWithPath(mnemonic: string, passphrase: string | null | undefined, path: string, network: string): Promise<any> {
await wasm.ensureInitialized();
return wasm.WasmSdk.deriveKeyFromSeedWithPath(mnemonic, passphrase ?? null, path, network);
}

export function deriveKeyFromSeedWithExtendedPath(mnemonic: string, passphrase: string | null | undefined, path: string, network: string): any {
export async function deriveKeyFromSeedWithExtendedPath(mnemonic: string, passphrase: string | null | undefined, path: string, network: string): Promise<any> {
await wasm.ensureInitialized();
return wasm.WasmSdk.deriveKeyFromSeedWithExtendedPath(mnemonic, passphrase ?? null, path, network);
}

export function deriveDashpayContactKey(mnemonic: string, passphrase: string | null | undefined, senderIdentityId: string, receiverIdentityId: string, account: number, addressIndex: number, network: string): any {
export async function deriveDashpayContactKey(mnemonic: string, passphrase: string | null | undefined, senderIdentityId: string, receiverIdentityId: string, account: number, addressIndex: number, network: string): Promise<any> {
await wasm.ensureInitialized();
return wasm.WasmSdk.deriveDashpayContactKey(
mnemonic,
passphrase ?? null,
Expand All @@ -37,63 +44,78 @@ export namespace wallet {
);
}

export function derivationPathBip44Mainnet(account: number, change: number, index: number): any {
export async function derivationPathBip44Mainnet(account: number, change: number, index: number): Promise<any> {
await wasm.ensureInitialized();
return wasm.WasmSdk.derivationPathBip44Mainnet(account, change, index);
}

export function derivationPathBip44Testnet(account: number, change: number, index: number): any {
export async function derivationPathBip44Testnet(account: number, change: number, index: number): Promise<any> {
await wasm.ensureInitialized();
return wasm.WasmSdk.derivationPathBip44Testnet(account, change, index);
}

export function derivationPathDip9Mainnet(featureType: number, account: number, index: number): any {
export async function derivationPathDip9Mainnet(featureType: number, account: number, index: number): Promise<any> {
await wasm.ensureInitialized();
return wasm.WasmSdk.derivationPathDip9Mainnet(featureType, account, index);
}

export function derivationPathDip9Testnet(featureType: number, account: number, index: number): any {
export async function derivationPathDip9Testnet(featureType: number, account: number, index: number): Promise<any> {
await wasm.ensureInitialized();
return wasm.WasmSdk.derivationPathDip9Testnet(featureType, account, index);
}

export function derivationPathDip13Mainnet(account: number): any {
export async function derivationPathDip13Mainnet(account: number): Promise<any> {
await wasm.ensureInitialized();
return wasm.WasmSdk.derivationPathDip13Mainnet(account);
}

export function derivationPathDip13Testnet(account: number): any {
export async function derivationPathDip13Testnet(account: number): Promise<any> {
await wasm.ensureInitialized();
return wasm.WasmSdk.derivationPathDip13Testnet(account);
}

export function deriveChildPublicKey(xpub: string, index: number, hardened: boolean): string {
export async function deriveChildPublicKey(xpub: string, index: number, hardened: boolean): Promise<string> {
await wasm.ensureInitialized();
return wasm.WasmSdk.deriveChildPublicKey(xpub, index, hardened);
}

export function xprvToXpub(xprv: string): string {
export async function xprvToXpub(xprv: string): Promise<string> {
await wasm.ensureInitialized();
return wasm.WasmSdk.xprvToXpub(xprv);
}

export function generateKeyPair(network: string): any {
export async function generateKeyPair(network: string): Promise<any> {
await wasm.ensureInitialized();
return wasm.WasmSdk.generateKeyPair(network);
}

export function generateKeyPairs(network: string, count: number): any[] {
export async function generateKeyPairs(network: string, count: number): Promise<any[]> {
await wasm.ensureInitialized();
return wasm.WasmSdk.generateKeyPairs(network, count);
}

export function keyPairFromWif(privateKeyWif: string): any {
export async function keyPairFromWif(privateKeyWif: string): Promise<any> {
await wasm.ensureInitialized();
return wasm.WasmSdk.keyPairFromWif(privateKeyWif);
}

export function keyPairFromHex(privateKeyHex: string, network: string): any {
export async function keyPairFromHex(privateKeyHex: string, network: string): Promise<any> {
await wasm.ensureInitialized();
return wasm.WasmSdk.keyPairFromHex(privateKeyHex, network);
}

export function pubkeyToAddress(pubkeyHex: string, network: string): string {
export async function pubkeyToAddress(pubkeyHex: string, network: string): Promise<string> {
await wasm.ensureInitialized();
return wasm.WasmSdk.pubkeyToAddress(pubkeyHex, network);
}

export function validateAddress(address: string, network: string): boolean {
export async function validateAddress(address: string, network: string): Promise<boolean> {
await wasm.ensureInitialized();
return wasm.WasmSdk.validateAddress(address, network);
}

export function signMessage(message: string, privateKeyWif: string): string {
export async function signMessage(message: string, privateKeyWif: string): Promise<string> {
await wasm.ensureInitialized();
return wasm.WasmSdk.signMessage(message, privateKeyWif);
}
}
1 change: 1 addition & 0 deletions packages/js-evo-sdk/src/wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export async function ensureInitialized(): Promise<void> {
// Re-export all wasm SDK symbols for convenience
export * from '@dashevo/wasm-sdk/compressed';
export { default } from '@dashevo/wasm-sdk/compressed';
export type { DataContract } from '@dashevo/wasm-sdk/compressed';
4 changes: 2 additions & 2 deletions packages/js-evo-sdk/tests/functional/tokens.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ describe('Tokens', function tokensSuite() {
await sdk.connect();
});

it('calculateId() derives token ID from contract', () => {
const id = sdk.tokens.calculateId(TEST_IDS.tokenContractId, 0);
it('calculateId() derives token ID from contract', async () => {
const id = await sdk.tokens.calculateId(TEST_IDS.tokenContractId, 0);
expect(id).to.equal(TEST_IDS.tokenId);
});

Expand Down
24 changes: 12 additions & 12 deletions packages/js-evo-sdk/tests/functional/wallet.spec.mjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { wallet } from '../../dist/evo-sdk.module.js';

describe('wallet helpers', () => {
it('generateMnemonic() returns phrase and validateMnemonic() succeeds', () => {
const mnemonic = wallet.generateMnemonic(12, 'en');
it('generateMnemonic() returns phrase and validateMnemonic() succeeds', async () => {
const mnemonic = await wallet.generateMnemonic(12, 'en');
expect(mnemonic).to.be.a('string');
expect(wallet.validateMnemonic(mnemonic, 'en')).to.equal(true);
expect(await wallet.validateMnemonic(mnemonic, 'en')).to.equal(true);
});

it('mnemonicToSeed() returns Uint8Array and derive functions respond', () => {
const mnemonic = wallet.generateMnemonic();
const seed = wallet.mnemonicToSeed(mnemonic);
it('mnemonicToSeed() returns Uint8Array and derive functions respond', async () => {
const mnemonic = await wallet.generateMnemonic();
const seed = await wallet.mnemonicToSeed(mnemonic);
expect(seed).to.be.instanceOf(Uint8Array);
expect(wallet.deriveKeyFromSeedPhrase(mnemonic, null, 'testnet')).to.exist();
expect(wallet.deriveKeyFromSeedWithPath(mnemonic, null, "m/44'/5'/0'", 'testnet')).to.exist();
expect(wallet.deriveKeyFromSeedWithExtendedPath(mnemonic, null, "m/15'/0'", 'testnet')).to.exist();
expect(await wallet.deriveKeyFromSeedPhrase(mnemonic, null, 'testnet')).to.exist();
expect(await wallet.deriveKeyFromSeedWithPath(mnemonic, null, "m/44'/5'/0'", 'testnet')).to.exist();
expect(await wallet.deriveKeyFromSeedWithExtendedPath(mnemonic, null, "m/15'/0'", 'testnet')).to.exist();
});

it('key utilities return expected shapes', () => {
const kp = wallet.generateKeyPair('testnet');
it('key utilities return expected shapes', async () => {
const kp = await wallet.generateKeyPair('testnet');
expect(kp).to.be.an('object');
const kps = wallet.generateKeyPairs('testnet', 2);
const kps = await wallet.generateKeyPairs('testnet', 2);
expect(kps).to.be.an('array');
});
});
12 changes: 6 additions & 6 deletions packages/js-evo-sdk/tests/unit/facades/dpns.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ describe('DPNSFacade', () => {
this.sinon.stub(wasmSdk, 'getDpnsUsernameByNameWithProofInfo').resolves({});
});

it('convertToHomographSafe/isValidUsername/isContestedUsername use class statics', () => {
const out1 = wasmSDKPackage.WasmSdk.dpnsConvertToHomographSafe('abc');
const out2 = wasmSDKPackage.WasmSdk.dpnsIsValidUsername('abc');
const out3 = wasmSDKPackage.WasmSdk.dpnsIsContestedUsername('abc');
it('convertToHomographSafe/isValidUsername/isContestedUsername await wasm statics', async () => {
const out1 = await client.dpns.convertToHomographSafe('abc');
const out2 = await client.dpns.isValidUsername('abc');
const out3 = await client.dpns.isContestedUsername('abc');
expect(out1).to.be.ok();
expect(typeof out2).to.not.equal('undefined');
expect(typeof out3).to.not.equal('undefined');
expect(out2).to.be.a('boolean');
expect(out3).to.be.a('boolean');
});

it('name resolution and registration forward correctly', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/js-evo-sdk/tests/unit/facades/tokens.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ describe('TokensFacade', () => {
this.sinon.stub(wasmSdk, 'tokenConfigUpdate').resolves('ok');
});

it('calculateId() uses wasm static helper', () => {
const out = client.tokens.calculateId('Hqyu8WcRwXCTwbNxdga4CN5gsVEGc67wng4TFzceyLUv', 0);
it('calculateId() uses wasm static helper', async () => {
const out = await client.tokens.calculateId('Hqyu8WcRwXCTwbNxdga4CN5gsVEGc67wng4TFzceyLUv', 0);
expect(out).to.equal('BpJvvpPiR2obh7ueZixjtYXsmWQdgJhiZtQJWjD7Ruus');
});

Expand Down
Loading