From 312782851d7a26946df9aa4cca703678c52a9899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haz=20=C3=86=2041?= <4405263+hazae41@users.noreply.github.com> Date: Mon, 20 May 2024 12:51:44 +0700 Subject: [PATCH] readme --- README.md | 28 ++++++++++++++++++++++++++++ src/mods/types/index.ts | 1 + 2 files changed, 29 insertions(+) diff --git a/README.md b/README.md index 6d4f14f..8bc09fd 100644 --- a/README.md +++ b/README.md @@ -241,4 +241,32 @@ const catAndDog = RlpList.from([cat, dog]) const bytes = Writable.writeToBytesOrThrow(catAndDog) const hex = "0x" + Base16.get().encodeOrThrow(bytes) +``` + +### Signing + +```tsx +import { Bytes } from "@hazae41/bytes" +import { ExtPrivateKey } from "@hazae41/cubane" +import { Secp256k1 } from "@hazae41/secp256k1" +import { Base16 } from "@hazae41/base16" + +const message = "hello world" + +const privateKeyBytes = Bytes.random(32) +const privateKeyExt = new ExtPrivateKey(Secp256k1.get().PrivateKey.importOrThrow(privateKeyBytes)) + +const signatureExt = privateKeyExt.signPersonalMessageOrThrow(message) +const signatureBytes = signatureExt.value.exportOrThrow().copyAndDispose() +const signatureZeroHex = `0x${Base16.get().encodeOrThrow(signatureBytes)}` +``` + +### Recovery + +```tsx +import { ExtPublicKey, Address } from "@hazae41/cubane" + +const recoveredPublicKeyExt = ExtPublicKey.recoverPersonalMessageOrThrow(message, signatureExt) +const recoveredPublicKeyBytes = recoveredPublicKeyExt.value.exportUncompressedOrThrow().copyAndDispose() +const recoveredAddressZeroHex = Address.computeOrThrow(recoveredPublicKeyBytes) ``` \ No newline at end of file diff --git a/src/mods/types/index.ts b/src/mods/types/index.ts index 079673a..f8a554d 100644 --- a/src/mods/types/index.ts +++ b/src/mods/types/index.ts @@ -1,5 +1,6 @@ export * from "./address/index.js"; export * from "./fixed/index.js"; +export * from "./helpers/index.js"; export * from "./signature/index.js"; export * from "./signer/index.js"; export * from "./string/index.js";