Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

chore: crypto util / wasm binding cleanup #116

Merged
merged 7 commits into from
Jun 17, 2022
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ _star.ts
benches.json
target
examples/generated
bindings/*/snippets
bindings/**/snippets
40 changes: 40 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ all = ["hashers", "sr25519", "ss58"]

[dependencies]
base58 = { version = "0.2.0" }
blake2 = "0.10.4"
console_error_panic_hook = { version = "0.1.7", optional = true }
frame-support = { version = "3.0.0" }
getrandom = { version = "0.2.5", features = ["js"] }
Expand Down
1 change: 1 addition & 0 deletions _deps/ss58_registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "https://esm.sh/v85/@substrate/ss58-registry@1.22.0/es2022/ss58-registry.js";
24 changes: 24 additions & 0 deletions _tasks/build_ss58_registry_literal_type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as path from "../_deps/path.ts";
import ss58Registry from "../_deps/ss58_registry.ts";

let generated = "// @generated file from build script, do not edit";
generated += "\nexport type Ss58Registry = ";
for (let i = 0; i < ss58Registry.length; i++) {
const current = ss58Registry[i]!;
if (i !== 0) {
generated += " | ";
}
generated += `{
prefix: ${current.prefix};
network: "${current.network}";
displayName: "${current.displayName}";
symbols: [${current.symbols.map((s) => `"${s}"`).join(", ")}];
decimals: [${current.decimals.join(", ")}];
standardAccount: "${current.standardAccount}";
website: "${current.website}";
}`;
}
generated += ";\n";
const dest = path.join(Deno.cwd(), "bindings/ss58/registry.ts");
console.log(`Writing "registry" file to "${dest}".`);
await Deno.writeTextFile(dest, generated);
1 change: 1 addition & 0 deletions bindings/hashers.rs → bindings/hashers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ macro_rules! make_hasher_binding {
};
}

// TODO: in what cases can these error out?
make_hasher_binding!(blake2_128, _blake2_128);
make_hasher_binding!(blake2_256, _blake2_256);
make_hasher_binding!(blake2_128Concat, <Blake2_128Concat as StorageHasher>::hash);
Expand Down
15 changes: 15 additions & 0 deletions bindings/hashers/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as M from "../../frame_metadata/mod.ts";
import { instantiate } from "./mod.generated.js";

export async function Hashers(): Promise<M.HasherLookup> {
const instance = await instantiate();
return {
Blake2_128: instance.blake2_128,
Blake2_128Concat: instance.blake2_128Concat,
Blake2_256: instance.blake2_256,
Identity: (x) => x,
Twox128: instance.twox128,
Twox256: instance.twox256,
Twox64Concat: instance.twox64Concat,
};
}
Binary file modified bindings/hashers/mod_bg.wasm
Binary file not shown.
22 changes: 3 additions & 19 deletions bindings/mod.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
import * as M from "../frame_metadata/mod.ts";

import * as hasherBindings from "./hashers/mod.generated.js";

export { instantiate as getSr25519 } from "./sr25519/mod.generated.js";
export { instantiate as getSs58 } from "./ss58/mod.generated.js";

export async function getHashers(): Promise<M.HasherLookup> {
await hasherBindings.instantiate();
return {
Blake2_128: hasherBindings.blake2_128,
Blake2_128Concat: hasherBindings.blake2_128Concat,
Blake2_256: hasherBindings.blake2_256,
Identity: (x) => x,
Twox128: hasherBindings.twox128,
Twox256: hasherBindings.twox256,
Twox64Concat: hasherBindings.twox64Concat,
};
}
export { Hashers } from "./hashers/mod.ts";
export { Sr25519 } from "./sr25519/mod.ts";
export { Ss58 } from "./ss58/mod.ts";
58 changes: 0 additions & 58 deletions bindings/sr25519.rs

This file was deleted.

Loading