Skip to content

Commit 5b0d752

Browse files
Use blake2b instead of blake2AsU8a
1 parent 8256bf4 commit 5b0d752

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

.snippets/code/develop/interoperability/xcm-observability/forward-id-for.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import {blake2AsU8a} from "@polkadot/util-crypto";
2-
import {hexToU8a, stringToU8a, u8aConcat, u8aToHex} from "@polkadot/util";
1+
import {blake2b} from "@noble/hashes/blake2";
2+
import {fromHex, mergeUint8, toHex} from "@polkadot-api/utils";
3+
import {Binary} from "polkadot-api";
34

45
function forwardIdFor(originalMessageId: string): string {
56
// Decode the hex original_id into bytes
6-
const messageIdBytes = hexToU8a(originalMessageId);
7+
const messageIdBytes = fromHex(originalMessageId);
78

89
// Create prefixed input: b"forward_id_for" + original_id
9-
const prefix = stringToU8a("forward_id_for");
10-
const input = u8aConcat(prefix, messageIdBytes);
11-
12-
// Hash it using blake2_256
13-
const forwardedIdBytes = blake2AsU8a(input);
10+
const prefix = Binary.fromText("forward_id_for").asBytes();
11+
const input = mergeUint8([prefix, messageIdBytes]);
1412

13+
// Hash it using blake2b with 32-byte output
14+
const forwardedIdBytes = blake2b(input, {dkLen: 32});
1515
// Convert to hex
16-
return u8aToHex(forwardedIdBytes);
16+
return toHex(forwardedIdBytes);
1717
}
1818

19-
// Example: Forwarded ID from a original_id
19+
// Example: Forwarded ID from an original_id
2020
const originalMessageId = "0x5c082b4750ee8c34986eb22ce6e345bad2360f3682cda3e99de94b0d9970cb3e";
2121

2222
// Create the forwarded ID

llms.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
- [Storage](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/develop/toolkit/integrations/storage.md): Explore decentralized storage solutions for your Polkadot dApp. Discover key integrations, such as Crust and IPFS, for robust, censorship-resistant data storage.
9090
- [Transaction Construction](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/develop/toolkit/integrations/transaction-construction.md): Understand how to construct, sign, and broadcast transactions in the Polkadot ecosystem using various tools and libraries.
9191
- [Wallets](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/develop/toolkit/integrations/wallets.md): Explore blockchain wallets. Securely manage digital assets with hot wallets for online access or cold wallets for offline, enhanced security.
92-
- [Interoperability](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/develop/toolkit/interoperability/index.md): Explore Polkadot's XCM tooling ecosystem, featuring the Asset Transfer API and other utilities for implementing cross-chain messaging and transfers.
92+
- [Interoperability](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/develop/toolkit/interoperability/index.md): Explore Polkadot's XCM tooling ecosystem, featuring utilities for implementing cross-chain messaging and transfers.
9393
- [ParaSpell XCM SDK](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/develop/toolkit/interoperability/paraspell-xcm-sdk/index.md): A powerful open-source library that simplifies XCM integration, enabling developers to easily build interoperable dApps on Polkadot.
9494
- [XCM Tools](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/develop/toolkit/interoperability/xcm-tools.md): Explore essential XCM tools across Polkadot, crafted to enhance cross-chain functionality and integration within the ecosystem.
9595
- [E2E Testing on Polkadot SDK Chains](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/develop/toolkit/parachains/e2e-testing/index.md): Discover a suite of tools for E2E testing on Polkadot SDK-based blockchains, including configuration management, automation, and debugging utilities.

tutorials/interoperability/xcm-observability-in-action.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ If you're new to replay or dry-run XCMs, see [Replay and Dry Run XCMs Using Chop
8686

8787
```bash
8888
npm install --save-dev typescript @types/node tsx
89-
npm install polkadot-api @polkadot-labs/hdkd @polkadot-labs/hdkd-helpers
89+
npm install polkadot-api @polkadot-labs/hdkd @polkadot-labs/hdkd-helpers
90+
npm install @noble/hashes
9091
```
9192

9293
9. Initialise TypeScript:

0 commit comments

Comments
 (0)