@veilux/sdk 0.3.8 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/encoding.d.ts +6 -0
- package/dist/encoding.js +11 -0
- package/dist/identity.d.ts +5 -0
- package/dist/identity.js +10 -2
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/dist/encoding.d.ts
CHANGED
|
@@ -14,6 +14,12 @@ export declare function visibilityJson(v: Visibility): Uint8Array;
|
|
|
14
14
|
* b"veilux/command/v1" 0xff prism 0xff submitter 0xff nonce_le vis 0xff payload
|
|
15
15
|
*/
|
|
16
16
|
export declare function signingBytes(cmd: Command): Uint8Array;
|
|
17
|
+
/**
|
|
18
|
+
* Chain-bound signing bytes (EIP-155 style). `chainId = 0` is identical to
|
|
19
|
+
* `signingBytes` (legacy/dev). A nonzero chain id appends a domain-separated
|
|
20
|
+
* suffix so a signature is only valid on its intended chain.
|
|
21
|
+
*/
|
|
22
|
+
export declare function signingBytesForChain(cmd: Command, chainId: number): Uint8Array;
|
|
17
23
|
/**
|
|
18
24
|
* Reproduce `Hash::commit(domain, parts)`:
|
|
19
25
|
* blake3(domain || 0xff || for each part: len_le_u64 || part)
|
package/dist/encoding.js
CHANGED
|
@@ -41,6 +41,17 @@ export function signingBytes(cmd) {
|
|
|
41
41
|
const sep = new Uint8Array([0xff]);
|
|
42
42
|
return concat(textEncoder.encode("veilux/command/v1"), sep, textEncoder.encode(cmd.prism), sep, textEncoder.encode(cmd.submitter), sep, u64le(cmd.nonce), visibilityJson(cmd.visibility), sep, Uint8Array.from(cmd.payload));
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Chain-bound signing bytes (EIP-155 style). `chainId = 0` is identical to
|
|
46
|
+
* `signingBytes` (legacy/dev). A nonzero chain id appends a domain-separated
|
|
47
|
+
* suffix so a signature is only valid on its intended chain.
|
|
48
|
+
*/
|
|
49
|
+
export function signingBytesForChain(cmd, chainId) {
|
|
50
|
+
const base = signingBytes(cmd);
|
|
51
|
+
if (chainId === 0)
|
|
52
|
+
return base;
|
|
53
|
+
return concat(base, new Uint8Array([0xff]), textEncoder.encode("chain"), u64le(chainId));
|
|
54
|
+
}
|
|
44
55
|
/**
|
|
45
56
|
* Reproduce `Hash::commit(domain, parts)`:
|
|
46
57
|
* blake3(domain || 0xff || for each part: len_le_u64 || part)
|
package/dist/identity.d.ts
CHANGED
|
@@ -20,4 +20,9 @@ export declare class PartyIdentity {
|
|
|
20
20
|
publicKey(): Uint8Array;
|
|
21
21
|
/** Sign a command, producing a SignedCommand ready for submission. */
|
|
22
22
|
sign(command: Command): SignedCommand;
|
|
23
|
+
/**
|
|
24
|
+
* Sign a command bound to a specific chain id (replay protection). Use the
|
|
25
|
+
* chain's `chain_id` (from `veilux_chainId` / genesis); 0 = legacy/dev.
|
|
26
|
+
*/
|
|
27
|
+
signForChain(command: Command, chainId: number): SignedCommand;
|
|
23
28
|
}
|
package/dist/identity.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as ed from "@noble/ed25519";
|
|
2
2
|
import { sha512 } from "@noble/hashes/sha512";
|
|
3
3
|
import { blake3 } from "@noble/hashes/blake3";
|
|
4
|
-
import {
|
|
4
|
+
import { signingBytesForChain } from "./encoding.js";
|
|
5
5
|
// @noble/ed25519 v2 needs sha512 wired up for synchronous signing.
|
|
6
6
|
ed.etc.sha512Sync = (...m) => sha512(ed.etc.concatBytes(...m));
|
|
7
7
|
/**
|
|
@@ -37,12 +37,20 @@ export class PartyIdentity {
|
|
|
37
37
|
}
|
|
38
38
|
/** Sign a command, producing a SignedCommand ready for submission. */
|
|
39
39
|
sign(command) {
|
|
40
|
-
|
|
40
|
+
return this.signForChain(command, 0);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Sign a command bound to a specific chain id (replay protection). Use the
|
|
44
|
+
* chain's `chain_id` (from `veilux_chainId` / genesis); 0 = legacy/dev.
|
|
45
|
+
*/
|
|
46
|
+
signForChain(command, chainId) {
|
|
47
|
+
const msg = signingBytesForChain(command, chainId);
|
|
41
48
|
const signature = ed.sign(msg, this.secret);
|
|
42
49
|
return {
|
|
43
50
|
command,
|
|
44
51
|
public_key: Array.from(this.publicKey()),
|
|
45
52
|
signature: Array.from(signature),
|
|
53
|
+
chain_id: chainId,
|
|
46
54
|
};
|
|
47
55
|
}
|
|
48
56
|
}
|
package/dist/types.d.ts
CHANGED