-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
MnemonicWallet
to allow programmatic signing and broadcas…
…ting of txs (#14) * feat: add working `signArbitrary` imple * refactor: shift some functions to codec * refactor: remove custom codec in favour of `@scure/base` * feat: add working `broadcastTx` * test: add tests * docs: add jsdocs * docs: add warning to readme * docs: add jsdocs to `ChainInfo`
- Loading branch information
Showing
35 changed files
with
516 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { resolveBech32Address } from "./address"; | ||
|
||
const PUB_KEY_1 = "A6Y9fcWSn5Av/HLHBwthTaVE/vdyRKvsTzi5U7j9bFj5"; // random pub pub key | ||
const PUB_KEY_2 = "Ag/a1BOl3cdwh67Z8iCbGmAu4WWmBwtuQlQMbDaN385V"; // coinhall.org val pubkey | ||
|
||
describe("resolveBech32Address", () => { | ||
it("should resolve stars address correctly", () => { | ||
const translated = resolveBech32Address(PUB_KEY_1, "stars"); | ||
expect(translated).toBe("stars14y420auq56p6xgt78sl8vwz3jxy77r9cuw900r"); | ||
}); | ||
|
||
it("should resolve cosmos address correctly", () => { | ||
const translated = resolveBech32Address(PUB_KEY_1, "cosmos"); | ||
expect(translated).toBe("cosmos14y420auq56p6xgt78sl8vwz3jxy77r9cgjjjyj"); | ||
}); | ||
|
||
it("should resolve terra address correctly", () => { | ||
const translated = resolveBech32Address(PUB_KEY_2, "terra"); | ||
expect(translated).toBe("terra1ge3vqn6cjkk2xkfwpg5ussjwxvahs2f6aytr5j"); | ||
}); | ||
|
||
it("should resolve terravaloper address correctly", () => { | ||
const translated = resolveBech32Address(PUB_KEY_2, "terravaloper"); | ||
expect(translated).toBe( | ||
"terravaloper1ge3vqn6cjkk2xkfwpg5ussjwxvahs2f6at87yp" | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ripemd160 } from "@noble/hashes/ripemd160"; | ||
import { sha256 } from "@noble/hashes/sha256"; | ||
import { base64, bech32 } from "@scure/base"; | ||
|
||
/** | ||
* Resolves the bech32 address from the given `publicKey` and `prefix`. | ||
* @param publicKey Must be either a base64 encoded string or a `Uint8Array`. | ||
*/ | ||
export function resolveBech32Address( | ||
publicKey: string | Uint8Array, | ||
prefix: string | ||
): string { | ||
const bytes = | ||
typeof publicKey === "string" ? base64.decode(publicKey) : publicKey; | ||
return bech32.encode(prefix, bech32.toWords(ripemd160(sha256(bytes)))); | ||
} |
Oops, something went wrong.