Skip to content

Commit

Permalink
feat(crypto-address-keccak256): implement fromWIF (#869)
Browse files Browse the repository at this point in the history
* Implement from WIF

* Add tests

* Fix test
  • Loading branch information
sebastijankuzner authored Feb 24, 2025
1 parent 35e9db0 commit 376010a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
7 changes: 7 additions & 0 deletions packages/crypto-address-base58/source/address.factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { describe } from "../../test-framework/source";
import { AddressFactory } from "./address.factory";

const mnemonic = "this is a top secret passphrase";
const wif = "SGq4xLgZKCGxs7bjmwnBrWcT4C1ADFEermj846KC97FSv1WFD1dA";

describe<{ app: Application }>("AddressFactory", ({ assert, beforeEach, it }) => {
beforeEach(async (context) => {
Expand Down Expand Up @@ -62,6 +63,12 @@ describe<{ app: Application }>("AddressFactory", ({ assert, beforeEach, it }) =>
);
});

it("should derive an address from wif", async (context) => {
await context.app.resolve<Schnorr>(Schnorr).register();

assert.is(await context.app.resolve(AddressFactory).fromWIF(wif), "D5jdQXLMgL2TumzdJ8B1zVAGtYWc43VQSx");
});

it("should validate addresses", async (context) => {
await context.app.resolve<ECDSA>(ECDSA).register();

Expand Down
11 changes: 9 additions & 2 deletions packages/crypto-address-keccak256/source/address.factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import { Identifiers } from "@mainsail/contracts";
import { Configuration } from "@mainsail/crypto-config";
import { ServiceProvider as ECDSA } from "@mainsail/crypto-key-pair-ecdsa";
import { ServiceProvider as Schnorr } from "@mainsail/crypto-key-pair-schnorr";
import { ServiceProvider as CoreValidation } from "@mainsail/validation";

import { Application } from "@mainsail/kernel";
import { ServiceProvider as CoreValidation } from "@mainsail/validation";

import { describe } from "../../test-framework/source";
import { AddressFactory } from "./address.factory";

const mnemonic =
"program fragile industry scare sun visit race erase daughter empty anxiety cereal cycle hunt airport educate giggle picture sunset apart jewel similar pulp moment";

const wif = "SDuW66dyGZ1zPZdN7ncEevbJdjaQTj9pT4LcmKzQ7eLFoyCXEdkx";

describe<{ app: Application }>("AddressFactory", ({ assert, beforeEach, it }) => {
beforeEach(async (context) => {
context.app = new Application(new Container());
Expand Down Expand Up @@ -61,6 +62,12 @@ describe<{ app: Application }>("AddressFactory", ({ assert, beforeEach, it }) =>
);
});

it("should derive an address from wif", async (context) => {
await context.app.resolve<Schnorr>(Schnorr).register();

assert.is(await context.app.resolve(AddressFactory).fromWIF(wif), "0x4D9AED240463043cFcf5B5Df16b9ad523930A181");
});

it("should validate addresses", async (context) => {
await context.app.resolve<ECDSA>(ECDSA).register();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class AddressFactory implements Contracts.Crypto.AddressFactory {
}

public async fromWIF(wif: string): Promise<string> {
return "";
return this.fromPublicKey(await this.publicKeyFactory.fromWIF(wif));
}

public async fromMultiSignatureAsset(asset: Contracts.Crypto.MultiSignatureAsset): Promise<string> {
Expand Down

0 comments on commit 376010a

Please sign in to comment.