tkdf256 1.0.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/LICENSE +7 -0
- package/README.md +31 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.js +122 -0
- package/dist/src/index.d.ts +74 -0
- package/dist/src/index.js +122 -0
- package/package.json +21 -0
package/LICENSE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# TKDF-256
|
|
2
|
+
|
|
3
|
+
Canonical reference implementation of TKDF-256 for CTP/IP (Causal Time Protocol / Intentional Processing).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install tkdf256
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { deriveHeritage } from 'tkdf256';
|
|
15
|
+
|
|
16
|
+
// Genesis Anchor reproduction
|
|
17
|
+
const result = deriveHeritage(
|
|
18
|
+
"1ed80be5bdf906eb259b04e9331fe4ec0cb3bc01aed5dbfb0bf9016c521825ea",
|
|
19
|
+
"c68d5bb2a8759ea332f642c6758d82ebbf8f0d6826f4182103b9a81a2b8f5af8",
|
|
20
|
+
0.9497
|
|
21
|
+
);
|
|
22
|
+
console.log(result); // c8041da8bbde4afe00906e6d0efb64300f90d2755b92b7835a736281fb179136
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## License
|
|
26
|
+
|
|
27
|
+
CC-BY-NC 4.0
|
|
28
|
+
Author: Erico Lisboa, Genesis Architect
|
|
29
|
+
Entity: Design Ledger Pty Ltd, ABN 50 669 856 339
|
|
30
|
+
Contact: designledger.co
|
|
31
|
+
Commercial use: licensed through Design Ledger Pty Ltd.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TKDF-256 - Transformation Key Derivation Function (Canonical Reference)
|
|
3
|
+
*
|
|
4
|
+
* License: CC-BY-NC 4.0
|
|
5
|
+
* Author: Erico Lisboa, Genesis Architect
|
|
6
|
+
* Entity: Design Ledger Pty Ltd, ABN 50 669 856 339
|
|
7
|
+
* Contact: designledger.co
|
|
8
|
+
* Commercial use: licensed through Design Ledger Pty Ltd.
|
|
9
|
+
*
|
|
10
|
+
* Canonical implementation of TKDF-256 for CTP/IP.
|
|
11
|
+
* Deterministic key derivation with byte-level concatenation and
|
|
12
|
+
* salt appended at end per foundational law T = Δ Σ ₀ Γ.
|
|
13
|
+
*/
|
|
14
|
+
/** Canonical use-case salts for TKDF-256 */
|
|
15
|
+
export declare const SALTS: {
|
|
16
|
+
readonly LOCK: "TKDF:LOCK";
|
|
17
|
+
readonly GOV: "TKDF:GOV";
|
|
18
|
+
readonly DID: "TKDF:DID";
|
|
19
|
+
readonly LIN: "TKDF:LIN";
|
|
20
|
+
readonly ZKT: "TKDF:ZKT";
|
|
21
|
+
readonly FLX: "TKDF:FLX";
|
|
22
|
+
readonly SWP: "TKDF:SWP";
|
|
23
|
+
readonly HER: "TKDF:HER";
|
|
24
|
+
readonly DAT: "TKDF:DAT";
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Convert number to IEEE-754 float64 big-endian bytes
|
|
28
|
+
*/
|
|
29
|
+
export declare function float64BE(value: number): Uint8Array;
|
|
30
|
+
/**
|
|
31
|
+
* Convert number to uint32 big-endian bytes
|
|
32
|
+
*/
|
|
33
|
+
export declare function uint32BE(value: number): Uint8Array;
|
|
34
|
+
/**
|
|
35
|
+
* Convert number to uint64 big-endian bytes
|
|
36
|
+
*/
|
|
37
|
+
export declare function uint64BE(value: number): Uint8Array;
|
|
38
|
+
/**
|
|
39
|
+
* Canonical TKDF-256 implementation
|
|
40
|
+
*
|
|
41
|
+
* Process: SHA-256(concat(inputs[0], inputs[1], ..., inputs[n], utf8(salt)))
|
|
42
|
+
*
|
|
43
|
+
* @param inputs - Array of raw byte arrays to concatenate
|
|
44
|
+
* @param salt - UTF-8 salt string appended at end
|
|
45
|
+
* @returns 64-character hex string
|
|
46
|
+
*/
|
|
47
|
+
export declare function tkdf256(inputs: Uint8Array[], salt: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Derive heritage hash using canonical TKDF-256
|
|
50
|
+
*
|
|
51
|
+
* Used for Genesis Anchor and heritage chain verification.
|
|
52
|
+
*
|
|
53
|
+
* @param evidenceHashHex - Evidence hash as hex string (64 chars)
|
|
54
|
+
* @param anchorHashHex - Anchor hash as hex string (64 chars)
|
|
55
|
+
* @param gamma - Gamma value as float
|
|
56
|
+
* @returns 64-character hex string
|
|
57
|
+
*/
|
|
58
|
+
export declare function deriveHeritage(evidenceHashHex: string, anchorHashHex: string, gamma: number): string;
|
|
59
|
+
/**
|
|
60
|
+
* Derive seal hash using canonical TKDF-256
|
|
61
|
+
*
|
|
62
|
+
* @param intentSigHex - Intent signature hash as hex string
|
|
63
|
+
* @param evidenceHex - Evidence hash as hex string
|
|
64
|
+
* @param gamma - Gamma value as float
|
|
65
|
+
* @param anchorHex - Anchor hash as hex string
|
|
66
|
+
* @returns 64-character hex string
|
|
67
|
+
*/
|
|
68
|
+
export declare function deriveSeal(intentSigHex: string, evidenceHex: string, gamma: number, anchorHex: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* Verify Genesis Anchor reproduction
|
|
71
|
+
*
|
|
72
|
+
* @returns true if Genesis Anchor hash matches canonical value
|
|
73
|
+
*/
|
|
74
|
+
export declare function verifyGenesisAnchor(): boolean;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TKDF-256 - Transformation Key Derivation Function (Canonical Reference)
|
|
3
|
+
*
|
|
4
|
+
* License: CC-BY-NC 4.0
|
|
5
|
+
* Author: Erico Lisboa, Genesis Architect
|
|
6
|
+
* Entity: Design Ledger Pty Ltd, ABN 50 669 856 339
|
|
7
|
+
* Contact: designledger.co
|
|
8
|
+
* Commercial use: licensed through Design Ledger Pty Ltd.
|
|
9
|
+
*
|
|
10
|
+
* Canonical implementation of TKDF-256 for CTP/IP.
|
|
11
|
+
* Deterministic key derivation with byte-level concatenation and
|
|
12
|
+
* salt appended at end per foundational law T = Δ Σ ₀ Γ.
|
|
13
|
+
*/
|
|
14
|
+
import { createHash } from 'crypto';
|
|
15
|
+
/** Canonical use-case salts for TKDF-256 */
|
|
16
|
+
export const SALTS = {
|
|
17
|
+
LOCK: "TKDF:LOCK",
|
|
18
|
+
GOV: "TKDF:GOV",
|
|
19
|
+
DID: "TKDF:DID",
|
|
20
|
+
LIN: "TKDF:LIN",
|
|
21
|
+
ZKT: "TKDF:ZKT",
|
|
22
|
+
FLX: "TKDF:FLX",
|
|
23
|
+
SWP: "TKDF:SWP",
|
|
24
|
+
HER: "TKDF:HER",
|
|
25
|
+
DAT: "TKDF:DAT"
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Convert number to IEEE-754 float64 big-endian bytes
|
|
29
|
+
*/
|
|
30
|
+
export function float64BE(value) {
|
|
31
|
+
const buffer = new ArrayBuffer(8);
|
|
32
|
+
new DataView(buffer).setFloat64(0, value, false); // false = big-endian
|
|
33
|
+
return new Uint8Array(buffer);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Convert number to uint32 big-endian bytes
|
|
37
|
+
*/
|
|
38
|
+
export function uint32BE(value) {
|
|
39
|
+
const buffer = new ArrayBuffer(4);
|
|
40
|
+
new DataView(buffer).setUint32(0, value, false); // false = big-endian
|
|
41
|
+
return new Uint8Array(buffer);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Convert number to uint64 big-endian bytes
|
|
45
|
+
*/
|
|
46
|
+
export function uint64BE(value) {
|
|
47
|
+
const buffer = new ArrayBuffer(8);
|
|
48
|
+
new DataView(buffer).setBigUint64(0, BigInt(value), false); // false = big-endian
|
|
49
|
+
return new Uint8Array(buffer);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Canonical TKDF-256 implementation
|
|
53
|
+
*
|
|
54
|
+
* Process: SHA-256(concat(inputs[0], inputs[1], ..., inputs[n], utf8(salt)))
|
|
55
|
+
*
|
|
56
|
+
* @param inputs - Array of raw byte arrays to concatenate
|
|
57
|
+
* @param salt - UTF-8 salt string appended at end
|
|
58
|
+
* @returns 64-character hex string
|
|
59
|
+
*/
|
|
60
|
+
export function tkdf256(inputs, salt) {
|
|
61
|
+
// Calculate total length
|
|
62
|
+
const saltBytes = new TextEncoder().encode(salt);
|
|
63
|
+
const totalLength = inputs.reduce((sum, input) => sum + input.length, 0) + saltBytes.length;
|
|
64
|
+
// Concatenate all inputs + salt
|
|
65
|
+
const preimage = new Uint8Array(totalLength);
|
|
66
|
+
let offset = 0;
|
|
67
|
+
for (const input of inputs) {
|
|
68
|
+
preimage.set(input, offset);
|
|
69
|
+
offset += input.length;
|
|
70
|
+
}
|
|
71
|
+
// Append salt at end
|
|
72
|
+
preimage.set(saltBytes, offset);
|
|
73
|
+
// Compute SHA-256
|
|
74
|
+
const hash = createHash('sha256');
|
|
75
|
+
hash.update(Buffer.from(preimage));
|
|
76
|
+
return hash.digest('hex');
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Derive heritage hash using canonical TKDF-256
|
|
80
|
+
*
|
|
81
|
+
* Used for Genesis Anchor and heritage chain verification.
|
|
82
|
+
*
|
|
83
|
+
* @param evidenceHashHex - Evidence hash as hex string (64 chars)
|
|
84
|
+
* @param anchorHashHex - Anchor hash as hex string (64 chars)
|
|
85
|
+
* @param gamma - Gamma value as float
|
|
86
|
+
* @returns 64-character hex string
|
|
87
|
+
*/
|
|
88
|
+
export function deriveHeritage(evidenceHashHex, anchorHashHex, gamma) {
|
|
89
|
+
const evidenceBytes = new Uint8Array(evidenceHashHex.match(/.{2}/g).map(hex => parseInt(hex, 16)));
|
|
90
|
+
const anchorBytes = new Uint8Array(anchorHashHex.match(/.{2}/g).map(hex => parseInt(hex, 16)));
|
|
91
|
+
const gammaBytes = float64BE(gamma);
|
|
92
|
+
return tkdf256([evidenceBytes, anchorBytes, gammaBytes], SALTS.HER);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Derive seal hash using canonical TKDF-256
|
|
96
|
+
*
|
|
97
|
+
* @param intentSigHex - Intent signature hash as hex string
|
|
98
|
+
* @param evidenceHex - Evidence hash as hex string
|
|
99
|
+
* @param gamma - Gamma value as float
|
|
100
|
+
* @param anchorHex - Anchor hash as hex string
|
|
101
|
+
* @returns 64-character hex string
|
|
102
|
+
*/
|
|
103
|
+
export function deriveSeal(intentSigHex, evidenceHex, gamma, anchorHex) {
|
|
104
|
+
const intentBytes = new Uint8Array(intentSigHex.match(/.{2}/g).map(hex => parseInt(hex, 16)));
|
|
105
|
+
const evidenceBytes = new Uint8Array(evidenceHex.match(/.{2}/g).map(hex => parseInt(hex, 16)));
|
|
106
|
+
const gammaBytes = float64BE(gamma);
|
|
107
|
+
const anchorBytes = new Uint8Array(anchorHex.match(/.{2}/g).map(hex => parseInt(hex, 16)));
|
|
108
|
+
return tkdf256([intentBytes, evidenceBytes, gammaBytes, anchorBytes], SALTS.DAT);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Verify Genesis Anchor reproduction
|
|
112
|
+
*
|
|
113
|
+
* @returns true if Genesis Anchor hash matches canonical value
|
|
114
|
+
*/
|
|
115
|
+
export function verifyGenesisAnchor() {
|
|
116
|
+
const GENESIS_EVIDENCE = "1ed80be5bdf906eb259b04e9331fe4ec0cb3bc01aed5dbfb0bf9016c521825ea";
|
|
117
|
+
const GENESIS_ANCHOR = "c68d5bb2a8759ea332f642c6758d82ebbf8f0d6826f4182103b9a81a2b8f5af8";
|
|
118
|
+
const GENESIS_GAMMA = 0.9497;
|
|
119
|
+
const EXPECTED_GENESIS_HASH = "c8041da8bbde4afe00906e6d0efb64300f90d2755b92b7835a736281fb179136";
|
|
120
|
+
const result = deriveHeritage(GENESIS_EVIDENCE, GENESIS_ANCHOR, GENESIS_GAMMA);
|
|
121
|
+
return result === EXPECTED_GENESIS_HASH;
|
|
122
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TKDF-256 - Transformation Key Derivation Function (Canonical Reference)
|
|
3
|
+
*
|
|
4
|
+
* License: CC-BY-NC 4.0
|
|
5
|
+
* Author: Erico Lisboa, Genesis Architect
|
|
6
|
+
* Entity: Design Ledger Pty Ltd, ABN 50 669 856 339
|
|
7
|
+
* Contact: designledger.co
|
|
8
|
+
* Commercial use: licensed through Design Ledger Pty Ltd.
|
|
9
|
+
*
|
|
10
|
+
* Canonical implementation of TKDF-256 for CTP/IP.
|
|
11
|
+
* Deterministic key derivation with byte-level concatenation and
|
|
12
|
+
* salt appended at end per foundational law T = Δ Σ ₀ Γ.
|
|
13
|
+
*/
|
|
14
|
+
/** Canonical use-case salts for TKDF-256 */
|
|
15
|
+
export declare const SALTS: {
|
|
16
|
+
readonly LOCK: "TKDF:LOCK";
|
|
17
|
+
readonly GOV: "TKDF:GOV";
|
|
18
|
+
readonly DID: "TKDF:DID";
|
|
19
|
+
readonly LIN: "TKDF:LIN";
|
|
20
|
+
readonly ZKT: "TKDF:ZKT";
|
|
21
|
+
readonly FLX: "TKDF:FLX";
|
|
22
|
+
readonly SWP: "TKDF:SWP";
|
|
23
|
+
readonly HER: "TKDF:HER";
|
|
24
|
+
readonly DAT: "TKDF:DAT";
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Convert number to IEEE-754 float64 big-endian bytes
|
|
28
|
+
*/
|
|
29
|
+
export declare function float64BE(value: number): Uint8Array;
|
|
30
|
+
/**
|
|
31
|
+
* Convert number to uint32 big-endian bytes
|
|
32
|
+
*/
|
|
33
|
+
export declare function uint32BE(value: number): Uint8Array;
|
|
34
|
+
/**
|
|
35
|
+
* Convert number to uint64 big-endian bytes
|
|
36
|
+
*/
|
|
37
|
+
export declare function uint64BE(value: number): Uint8Array;
|
|
38
|
+
/**
|
|
39
|
+
* Canonical TKDF-256 implementation
|
|
40
|
+
*
|
|
41
|
+
* Process: SHA-256(concat(inputs[0], inputs[1], ..., inputs[n], utf8(salt)))
|
|
42
|
+
*
|
|
43
|
+
* @param inputs - Array of raw byte arrays to concatenate
|
|
44
|
+
* @param salt - UTF-8 salt string appended at end
|
|
45
|
+
* @returns 64-character hex string
|
|
46
|
+
*/
|
|
47
|
+
export declare function tkdf256(inputs: Uint8Array[], salt: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Derive heritage hash using canonical TKDF-256
|
|
50
|
+
*
|
|
51
|
+
* Used for Genesis Anchor and heritage chain verification.
|
|
52
|
+
*
|
|
53
|
+
* @param evidenceHashHex - Evidence hash as hex string (64 chars)
|
|
54
|
+
* @param anchorHashHex - Anchor hash as hex string (64 chars)
|
|
55
|
+
* @param gamma - Gamma value as float
|
|
56
|
+
* @returns 64-character hex string
|
|
57
|
+
*/
|
|
58
|
+
export declare function deriveHeritage(evidenceHashHex: string, anchorHashHex: string, gamma: number): string;
|
|
59
|
+
/**
|
|
60
|
+
* Derive seal hash using canonical TKDF-256
|
|
61
|
+
*
|
|
62
|
+
* @param intentSigHex - Intent signature hash as hex string
|
|
63
|
+
* @param evidenceHex - Evidence hash as hex string
|
|
64
|
+
* @param gamma - Gamma value as float
|
|
65
|
+
* @param anchorHex - Anchor hash as hex string
|
|
66
|
+
* @returns 64-character hex string
|
|
67
|
+
*/
|
|
68
|
+
export declare function deriveSeal(intentSigHex: string, evidenceHex: string, gamma: number, anchorHex: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* Verify Genesis Anchor reproduction
|
|
71
|
+
*
|
|
72
|
+
* @returns true if Genesis Anchor hash matches canonical value
|
|
73
|
+
*/
|
|
74
|
+
export declare function verifyGenesisAnchor(): boolean;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TKDF-256 - Transformation Key Derivation Function (Canonical Reference)
|
|
3
|
+
*
|
|
4
|
+
* License: CC-BY-NC 4.0
|
|
5
|
+
* Author: Erico Lisboa, Genesis Architect
|
|
6
|
+
* Entity: Design Ledger Pty Ltd, ABN 50 669 856 339
|
|
7
|
+
* Contact: designledger.co
|
|
8
|
+
* Commercial use: licensed through Design Ledger Pty Ltd.
|
|
9
|
+
*
|
|
10
|
+
* Canonical implementation of TKDF-256 for CTP/IP.
|
|
11
|
+
* Deterministic key derivation with byte-level concatenation and
|
|
12
|
+
* salt appended at end per foundational law T = Δ Σ ₀ Γ.
|
|
13
|
+
*/
|
|
14
|
+
import { createHash } from 'crypto';
|
|
15
|
+
/** Canonical use-case salts for TKDF-256 */
|
|
16
|
+
export const SALTS = {
|
|
17
|
+
LOCK: "TKDF:LOCK",
|
|
18
|
+
GOV: "TKDF:GOV",
|
|
19
|
+
DID: "TKDF:DID",
|
|
20
|
+
LIN: "TKDF:LIN",
|
|
21
|
+
ZKT: "TKDF:ZKT",
|
|
22
|
+
FLX: "TKDF:FLX",
|
|
23
|
+
SWP: "TKDF:SWP",
|
|
24
|
+
HER: "TKDF:HER",
|
|
25
|
+
DAT: "TKDF:DAT"
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Convert number to IEEE-754 float64 big-endian bytes
|
|
29
|
+
*/
|
|
30
|
+
export function float64BE(value) {
|
|
31
|
+
const buffer = new ArrayBuffer(8);
|
|
32
|
+
new DataView(buffer).setFloat64(0, value, false); // false = big-endian
|
|
33
|
+
return new Uint8Array(buffer);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Convert number to uint32 big-endian bytes
|
|
37
|
+
*/
|
|
38
|
+
export function uint32BE(value) {
|
|
39
|
+
const buffer = new ArrayBuffer(4);
|
|
40
|
+
new DataView(buffer).setUint32(0, value, false); // false = big-endian
|
|
41
|
+
return new Uint8Array(buffer);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Convert number to uint64 big-endian bytes
|
|
45
|
+
*/
|
|
46
|
+
export function uint64BE(value) {
|
|
47
|
+
const buffer = new ArrayBuffer(8);
|
|
48
|
+
new DataView(buffer).setBigUint64(0, BigInt(value), false); // false = big-endian
|
|
49
|
+
return new Uint8Array(buffer);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Canonical TKDF-256 implementation
|
|
53
|
+
*
|
|
54
|
+
* Process: SHA-256(concat(inputs[0], inputs[1], ..., inputs[n], utf8(salt)))
|
|
55
|
+
*
|
|
56
|
+
* @param inputs - Array of raw byte arrays to concatenate
|
|
57
|
+
* @param salt - UTF-8 salt string appended at end
|
|
58
|
+
* @returns 64-character hex string
|
|
59
|
+
*/
|
|
60
|
+
export function tkdf256(inputs, salt) {
|
|
61
|
+
// Calculate total length
|
|
62
|
+
const saltBytes = new TextEncoder().encode(salt);
|
|
63
|
+
const totalLength = inputs.reduce((sum, input) => sum + input.length, 0) + saltBytes.length;
|
|
64
|
+
// Concatenate all inputs + salt
|
|
65
|
+
const preimage = new Uint8Array(totalLength);
|
|
66
|
+
let offset = 0;
|
|
67
|
+
for (const input of inputs) {
|
|
68
|
+
preimage.set(input, offset);
|
|
69
|
+
offset += input.length;
|
|
70
|
+
}
|
|
71
|
+
// Append salt at end
|
|
72
|
+
preimage.set(saltBytes, offset);
|
|
73
|
+
// Compute SHA-256
|
|
74
|
+
const hash = createHash('sha256');
|
|
75
|
+
hash.update(Buffer.from(preimage));
|
|
76
|
+
return hash.digest('hex');
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Derive heritage hash using canonical TKDF-256
|
|
80
|
+
*
|
|
81
|
+
* Used for Genesis Anchor and heritage chain verification.
|
|
82
|
+
*
|
|
83
|
+
* @param evidenceHashHex - Evidence hash as hex string (64 chars)
|
|
84
|
+
* @param anchorHashHex - Anchor hash as hex string (64 chars)
|
|
85
|
+
* @param gamma - Gamma value as float
|
|
86
|
+
* @returns 64-character hex string
|
|
87
|
+
*/
|
|
88
|
+
export function deriveHeritage(evidenceHashHex, anchorHashHex, gamma) {
|
|
89
|
+
const evidenceBytes = new Uint8Array(evidenceHashHex.match(/.{2}/g).map(hex => parseInt(hex, 16)));
|
|
90
|
+
const anchorBytes = new Uint8Array(anchorHashHex.match(/.{2}/g).map(hex => parseInt(hex, 16)));
|
|
91
|
+
const gammaBytes = float64BE(gamma);
|
|
92
|
+
return tkdf256([evidenceBytes, anchorBytes, gammaBytes], SALTS.HER);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Derive seal hash using canonical TKDF-256
|
|
96
|
+
*
|
|
97
|
+
* @param intentSigHex - Intent signature hash as hex string
|
|
98
|
+
* @param evidenceHex - Evidence hash as hex string
|
|
99
|
+
* @param gamma - Gamma value as float
|
|
100
|
+
* @param anchorHex - Anchor hash as hex string
|
|
101
|
+
* @returns 64-character hex string
|
|
102
|
+
*/
|
|
103
|
+
export function deriveSeal(intentSigHex, evidenceHex, gamma, anchorHex) {
|
|
104
|
+
const intentBytes = new Uint8Array(intentSigHex.match(/.{2}/g).map(hex => parseInt(hex, 16)));
|
|
105
|
+
const evidenceBytes = new Uint8Array(evidenceHex.match(/.{2}/g).map(hex => parseInt(hex, 16)));
|
|
106
|
+
const gammaBytes = float64BE(gamma);
|
|
107
|
+
const anchorBytes = new Uint8Array(anchorHex.match(/.{2}/g).map(hex => parseInt(hex, 16)));
|
|
108
|
+
return tkdf256([intentBytes, evidenceBytes, gammaBytes, anchorBytes], SALTS.DAT);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Verify Genesis Anchor reproduction
|
|
112
|
+
*
|
|
113
|
+
* @returns true if Genesis Anchor hash matches canonical value
|
|
114
|
+
*/
|
|
115
|
+
export function verifyGenesisAnchor() {
|
|
116
|
+
const GENESIS_EVIDENCE = "1ed80be5bdf906eb259b04e9331fe4ec0cb3bc01aed5dbfb0bf9016c521825ea";
|
|
117
|
+
const GENESIS_ANCHOR = "c68d5bb2a8759ea332f642c6758d82ebbf8f0d6826f4182103b9a81a2b8f5af8";
|
|
118
|
+
const GENESIS_GAMMA = 0.9497;
|
|
119
|
+
const EXPECTED_GENESIS_HASH = "c8041da8bbde4afe00906e6d0efb64300f90d2755b92b7835a736281fb179136";
|
|
120
|
+
const result = deriveHeritage(GENESIS_EVIDENCE, GENESIS_ANCHOR, GENESIS_GAMMA);
|
|
121
|
+
return result === EXPECTED_GENESIS_HASH;
|
|
122
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tkdf256",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Canonical reference implementation of TKDF-256 for CTP/IP",
|
|
6
|
+
"author": "Erico Lisboa (Design Ledger Pty Ltd, ABN 50 669 856 339)",
|
|
7
|
+
"license": "CC-BY-NC-4.0",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"test": "node --test test/*.test.mjs"
|
|
13
|
+
},
|
|
14
|
+
"files": ["dist", "LICENSE", "README.md"],
|
|
15
|
+
"engines": { "node": ">=18" },
|
|
16
|
+
"keywords": ["ctpip", "tkdf256", "hash", "key-derivation"],
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/node": "^25.7.0",
|
|
19
|
+
"typescript": "^6.0.3"
|
|
20
|
+
}
|
|
21
|
+
}
|