@hathor/ct-crypto-node 0.3.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/index.d.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/// Type declarations for @hathor/ct-crypto-node NAPI addon
|
|
2
|
+
|
|
3
|
+
// Generator / tag derivation
|
|
4
|
+
export function deriveAssetTag(tokenUid: Buffer): Buffer;
|
|
5
|
+
export function htrAssetTag(): Buffer;
|
|
6
|
+
export function deriveTag(tokenUid: Buffer): Buffer;
|
|
7
|
+
export function createAssetCommitment(tagBytes: Buffer, rAsset: Buffer): Buffer;
|
|
8
|
+
|
|
9
|
+
// Pedersen commitments
|
|
10
|
+
export function createCommitment(amount: bigint, blinding: Buffer, generator: Buffer): Buffer;
|
|
11
|
+
export function createTrivialCommitment(amount: bigint, generator: Buffer): Buffer;
|
|
12
|
+
export function verifyCommitmentsSum(positive: Buffer[], negative: Buffer[]): boolean;
|
|
13
|
+
|
|
14
|
+
// Range proofs
|
|
15
|
+
export function createRangeProof(
|
|
16
|
+
amount: bigint, blinding: Buffer, commitment: Buffer, generator: Buffer,
|
|
17
|
+
message?: Buffer | null, nonce?: Buffer | null,
|
|
18
|
+
): Buffer;
|
|
19
|
+
export function verifyRangeProof(proof: Buffer, commitment: Buffer, generator: Buffer): boolean;
|
|
20
|
+
|
|
21
|
+
export interface RewindResult {
|
|
22
|
+
value: bigint;
|
|
23
|
+
blindingFactor: Buffer;
|
|
24
|
+
message: Buffer;
|
|
25
|
+
}
|
|
26
|
+
export function rewindRangeProof(
|
|
27
|
+
proof: Buffer, commitment: Buffer, nonce: Buffer, generator: Buffer,
|
|
28
|
+
): RewindResult;
|
|
29
|
+
|
|
30
|
+
// Validation
|
|
31
|
+
export function validateCommitment(data: Buffer): boolean;
|
|
32
|
+
export function validateGenerator(data: Buffer): boolean;
|
|
33
|
+
|
|
34
|
+
// Surjection proofs
|
|
35
|
+
export interface SurjectionDomainEntry {
|
|
36
|
+
generator: Buffer;
|
|
37
|
+
tag: Buffer;
|
|
38
|
+
blindingFactor: Buffer;
|
|
39
|
+
}
|
|
40
|
+
export function createSurjectionProof(
|
|
41
|
+
codomainTag: Buffer, codomainBlindingFactor: Buffer, domain: SurjectionDomainEntry[],
|
|
42
|
+
): Buffer;
|
|
43
|
+
export function verifySurjectionProof(proof: Buffer, codomain: Buffer, domain: Buffer[]): boolean;
|
|
44
|
+
|
|
45
|
+
// Balance verification
|
|
46
|
+
export interface TransparentEntry {
|
|
47
|
+
amount: bigint;
|
|
48
|
+
tokenUid: Buffer;
|
|
49
|
+
}
|
|
50
|
+
export function verifyBalance(
|
|
51
|
+
transparentInputs: TransparentEntry[], shieldedInputs: Buffer[],
|
|
52
|
+
transparentOutputs: TransparentEntry[], shieldedOutputs: Buffer[],
|
|
53
|
+
): boolean;
|
|
54
|
+
|
|
55
|
+
// Blinding factor management
|
|
56
|
+
export interface BlindingEntry {
|
|
57
|
+
value: bigint;
|
|
58
|
+
valueBlindingFactor: Buffer;
|
|
59
|
+
generatorBlindingFactor: Buffer;
|
|
60
|
+
}
|
|
61
|
+
export function computeBalancingBlindingFactor(
|
|
62
|
+
value: bigint, generatorBlindingFactor: Buffer,
|
|
63
|
+
inputs: BlindingEntry[], otherOutputs: BlindingEntry[],
|
|
64
|
+
): Buffer;
|
|
65
|
+
|
|
66
|
+
// Random generation
|
|
67
|
+
export function generateRandomBlindingFactor(): Buffer;
|
|
68
|
+
|
|
69
|
+
export interface EphemeralKeypair {
|
|
70
|
+
privateKey: Buffer;
|
|
71
|
+
publicKey: Buffer;
|
|
72
|
+
}
|
|
73
|
+
export function generateEphemeralKeypair(): EphemeralKeypair;
|
|
74
|
+
|
|
75
|
+
// ECDH
|
|
76
|
+
export function deriveEcdhSharedSecret(privateKey: Buffer, peerPubkey: Buffer): Buffer;
|
|
77
|
+
export function deriveRewindNonce(sharedSecret: Buffer): Buffer;
|
|
78
|
+
|
|
79
|
+
// Shielded output creation
|
|
80
|
+
export interface CreatedAmountShieldedOutput {
|
|
81
|
+
ephemeralPubkey: Buffer;
|
|
82
|
+
commitment: Buffer;
|
|
83
|
+
rangeProof: Buffer;
|
|
84
|
+
blindingFactor: Buffer;
|
|
85
|
+
}
|
|
86
|
+
export function createAmountShieldedOutput(
|
|
87
|
+
value: bigint, recipientPubkey: Buffer, tokenUid: Buffer, valueBlindingFactor: Buffer,
|
|
88
|
+
): CreatedAmountShieldedOutput;
|
|
89
|
+
|
|
90
|
+
export interface CreatedShieldedOutput {
|
|
91
|
+
ephemeralPubkey: Buffer;
|
|
92
|
+
commitment: Buffer;
|
|
93
|
+
rangeProof: Buffer;
|
|
94
|
+
blindingFactor: Buffer;
|
|
95
|
+
assetCommitment: Buffer | null;
|
|
96
|
+
assetBlindingFactor: Buffer | null;
|
|
97
|
+
}
|
|
98
|
+
export function createShieldedOutputWithBothBlindings(
|
|
99
|
+
value: bigint, recipientPubkey: Buffer, tokenUid: Buffer,
|
|
100
|
+
valueBlindingFactor: Buffer, assetBlindingFactor: Buffer,
|
|
101
|
+
): CreatedShieldedOutput;
|
|
102
|
+
|
|
103
|
+
// Shielded output rewind
|
|
104
|
+
export interface RewoundAmountShieldedOutput {
|
|
105
|
+
value: bigint;
|
|
106
|
+
blindingFactor: Buffer;
|
|
107
|
+
}
|
|
108
|
+
export function rewindAmountShieldedOutput(
|
|
109
|
+
privateKey: Buffer, ephemeralPubkey: Buffer, commitment: Buffer,
|
|
110
|
+
rangeProof: Buffer, tokenUid: Buffer,
|
|
111
|
+
): RewoundAmountShieldedOutput;
|
|
112
|
+
|
|
113
|
+
export interface RewoundFullShieldedOutput {
|
|
114
|
+
value: bigint;
|
|
115
|
+
blindingFactor: Buffer;
|
|
116
|
+
tokenUid: Buffer;
|
|
117
|
+
assetBlindingFactor: Buffer;
|
|
118
|
+
}
|
|
119
|
+
export function rewindFullShieldedOutput(
|
|
120
|
+
privateKey: Buffer, ephemeralPubkey: Buffer, commitment: Buffer,
|
|
121
|
+
rangeProof: Buffer, assetCommitment: Buffer,
|
|
122
|
+
): RewoundFullShieldedOutput;
|
|
123
|
+
|
|
124
|
+
// Constants
|
|
125
|
+
export function getCommitmentSize(): number;
|
|
126
|
+
export function getGeneratorSize(): number;
|
|
127
|
+
export function getZeroTweak(): Buffer;
|
|
128
|
+
|
|
129
|
+
export function loadNative(): typeof import('@hathor/ct-crypto-node');
|
package/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loader for @hathor/ct-crypto-node NAPI addon.
|
|
3
|
+
* Loads the prebuilt .node binary for the current platform.
|
|
4
|
+
*/
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const os = require('os');
|
|
9
|
+
|
|
10
|
+
function loadNative() {
|
|
11
|
+
const platform = os.platform();
|
|
12
|
+
const arch = os.arch();
|
|
13
|
+
const prebuildPath = path.join(
|
|
14
|
+
__dirname, 'prebuilds', `${platform}-${arch}`, 'ct-crypto.node'
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
return require(prebuildPath);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`Failed to load @hathor/ct-crypto-node native addon for ${platform}-${arch}.\n` +
|
|
22
|
+
`Tried: ${prebuildPath}\n` +
|
|
23
|
+
`Error: ${e.message}\n\n` +
|
|
24
|
+
`Make sure the prebuild for your platform is included in the package.\n` +
|
|
25
|
+
`Supported platforms: darwin-arm64, darwin-x64, linux-x64, linux-arm64`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Load and re-export all NAPI functions
|
|
31
|
+
const native = loadNative();
|
|
32
|
+
module.exports = native;
|
|
33
|
+
module.exports.loadNative = loadNative;
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hathor/ct-crypto-node",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Hathor confidential transaction cryptography — NAPI native addon for Node.js",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"index.js",
|
|
9
|
+
"index.d.ts",
|
|
10
|
+
"prebuilds/"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "cargo build --features napi --release",
|
|
14
|
+
"build:debug": "cargo build --features napi"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/HathorNetwork/hathor-ct-crypto.git"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"hathor",
|
|
22
|
+
"confidential-transactions",
|
|
23
|
+
"pedersen",
|
|
24
|
+
"bulletproofs",
|
|
25
|
+
"secp256k1",
|
|
26
|
+
"napi"
|
|
27
|
+
],
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18"
|
|
31
|
+
},
|
|
32
|
+
"os": [
|
|
33
|
+
"darwin",
|
|
34
|
+
"linux",
|
|
35
|
+
"win32"
|
|
36
|
+
],
|
|
37
|
+
"cpu": [
|
|
38
|
+
"x64",
|
|
39
|
+
"arm64"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|