Skip to content

Commit 131180f

Browse files
Use blake2b instead of blake2AsU8a
1 parent 5b0d752 commit 131180f

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

llms-full.txt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3267,25 +3267,25 @@ fn forward_id_for(original_id: &XcmHash) -> XcmHash {
32673267
Tools and indexers tracing messages across mixed runtime versions should check **both** the original and forwarded IDs.
32683268

32693269
```ts
3270-
import {blake2AsU8a} from "@polkadot/util-crypto";
3271-
import {hexToU8a, stringToU8a, u8aConcat, u8aToHex} from "@polkadot/util";
3270+
import {blake2b} from "@noble/hashes/blake2";
3271+
import {fromHex, mergeUint8, toHex} from "@polkadot-api/utils";
3272+
import {Binary} from "polkadot-api";
32723273

32733274
function forwardIdFor(originalMessageId: string): string {
32743275
// Decode the hex original_id into bytes
3275-
const messageIdBytes = hexToU8a(originalMessageId);
3276+
const messageIdBytes = fromHex(originalMessageId);
32763277

32773278
// Create prefixed input: b"forward_id_for" + original_id
3278-
const prefix = stringToU8a("forward_id_for");
3279-
const input = u8aConcat(prefix, messageIdBytes);
3280-
3281-
// Hash it using blake2_256
3282-
const forwardedIdBytes = blake2AsU8a(input);
3279+
const prefix = Binary.fromText("forward_id_for").asBytes();
3280+
const input = mergeUint8([prefix, messageIdBytes]);
32833281

3282+
// Hash it using blake2b with 32-byte output
3283+
const forwardedIdBytes = blake2b(input, {dkLen: 32});
32843284
// Convert to hex
3285-
return u8aToHex(forwardedIdBytes);
3285+
return toHex(forwardedIdBytes);
32863286
}
32873287

3288-
// Example: Forwarded ID from a original_id
3288+
// Example: Forwarded ID from an original_id
32893289
const originalMessageId = "0x5c082b4750ee8c34986eb22ce6e345bad2360f3682cda3e99de94b0d9970cb3e";
32903290

32913291
// Create the forwarded ID
@@ -31160,7 +31160,8 @@ If you're new to replay or dry-run XCMs, see [Replay and Dry Run XCMs Using Chop
3116031160

3116131161
```bash
3116231162
npm install --save-dev typescript @types/node tsx
31163-
npm install polkadot-api @polkadot-labs/hdkd @polkadot-labs/hdkd-helpers
31163+
npm install polkadot-api @polkadot-labs/hdkd @polkadot-labs/hdkd-helpers
31164+
npm install @noble/hashes
3116431165
```
3116531166

3116631167
9. Initialise TypeScript:

0 commit comments

Comments
 (0)