@velumdotcash/sdk 2.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 +21 -0
- package/README.md +142 -0
- package/dist/__tests__/paylink.test.d.ts +9 -0
- package/dist/__tests__/paylink.test.js +254 -0
- package/dist/config.d.ts +9 -0
- package/dist/config.js +12 -0
- package/dist/deposit.d.ts +22 -0
- package/dist/deposit.js +445 -0
- package/dist/depositSPL.d.ts +24 -0
- package/dist/depositSPL.js +499 -0
- package/dist/errors.d.ts +78 -0
- package/dist/errors.js +127 -0
- package/dist/exportUtils.d.ts +10 -0
- package/dist/exportUtils.js +10 -0
- package/dist/getUtxos.d.ts +30 -0
- package/dist/getUtxos.js +335 -0
- package/dist/getUtxosSPL.d.ts +34 -0
- package/dist/getUtxosSPL.js +442 -0
- package/dist/index.d.ts +183 -0
- package/dist/index.js +436 -0
- package/dist/models/keypair.d.ts +26 -0
- package/dist/models/keypair.js +43 -0
- package/dist/models/utxo.d.ts +51 -0
- package/dist/models/utxo.js +99 -0
- package/dist/test_paylink_logic.test.d.ts +1 -0
- package/dist/test_paylink_logic.test.js +114 -0
- package/dist/utils/address_lookup_table.d.ts +9 -0
- package/dist/utils/address_lookup_table.js +45 -0
- package/dist/utils/constants.d.ts +27 -0
- package/dist/utils/constants.js +56 -0
- package/dist/utils/debug-logger.d.ts +250 -0
- package/dist/utils/debug-logger.js +688 -0
- package/dist/utils/encryption.d.ts +152 -0
- package/dist/utils/encryption.js +700 -0
- package/dist/utils/logger.d.ts +9 -0
- package/dist/utils/logger.js +35 -0
- package/dist/utils/merkle_tree.d.ts +92 -0
- package/dist/utils/merkle_tree.js +186 -0
- package/dist/utils/node-shim.d.ts +14 -0
- package/dist/utils/node-shim.js +21 -0
- package/dist/utils/prover.d.ts +36 -0
- package/dist/utils/prover.js +169 -0
- package/dist/utils/utils.d.ts +64 -0
- package/dist/utils/utils.js +165 -0
- package/dist/withdraw.d.ts +22 -0
- package/dist/withdraw.js +290 -0
- package/dist/withdrawSPL.d.ts +24 -0
- package/dist/withdrawSPL.js +329 -0
- package/package.json +59 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { Keypair } from '@solana/web3.js';
|
|
2
|
+
import { Utxo } from '../models/utxo.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a UTXO with minimal required fields
|
|
5
|
+
*/
|
|
6
|
+
export interface UtxoData {
|
|
7
|
+
amount: string;
|
|
8
|
+
blinding: string;
|
|
9
|
+
index: number | string;
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}
|
|
12
|
+
export interface EncryptionKey {
|
|
13
|
+
v1: Uint8Array;
|
|
14
|
+
v2: Uint8Array;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Service for handling encryption and decryption of UTXO data
|
|
18
|
+
*/
|
|
19
|
+
export declare class EncryptionService {
|
|
20
|
+
static readonly ENCRYPTION_VERSION_V2: Buffer<ArrayBuffer>;
|
|
21
|
+
static readonly ENCRYPTION_VERSION_V3: Buffer<ArrayBuffer>;
|
|
22
|
+
static readonly SIGNATURE_SCHEMA_VERSION: Buffer<ArrayBuffer>;
|
|
23
|
+
static readonly RECIPIENT_ID_LENGTH = 8;
|
|
24
|
+
private encryptionKeyV1;
|
|
25
|
+
private encryptionKeyV2;
|
|
26
|
+
private asymmetricSecretKey;
|
|
27
|
+
private utxoPrivateKeyV1;
|
|
28
|
+
private utxoPrivateKeyV2;
|
|
29
|
+
private walletAddress;
|
|
30
|
+
/**
|
|
31
|
+
* Generate an encryption key from a signature
|
|
32
|
+
* @param signature The user's signature
|
|
33
|
+
* @param walletAddress Optional wallet address for logging/verification
|
|
34
|
+
* @returns The generated encryption key
|
|
35
|
+
*/
|
|
36
|
+
deriveEncryptionKeyFromSignature(signature: Uint8Array, walletAddress?: string): EncryptionKey;
|
|
37
|
+
/**
|
|
38
|
+
* Generate an encryption key from a wallet keypair (V2 format)
|
|
39
|
+
* @param keypair The Solana keypair to derive the encryption key from
|
|
40
|
+
* @returns The generated encryption key
|
|
41
|
+
*/
|
|
42
|
+
deriveEncryptionKeyFromWallet(keypair: Keypair): EncryptionKey;
|
|
43
|
+
/**
|
|
44
|
+
* Get the Asymmetric Public Key (X25519) derived from the encryption key
|
|
45
|
+
*/
|
|
46
|
+
getAsymmetricPublicKey(): Uint8Array;
|
|
47
|
+
/**
|
|
48
|
+
* Derive recipient ID hash from X25519 public key
|
|
49
|
+
* Used for O(1) early termination during UTXO decryption
|
|
50
|
+
* @param publicKey Optional X25519 public key. If not provided, uses own public key.
|
|
51
|
+
* @returns First 8 bytes of SHA256(publicKey)
|
|
52
|
+
*/
|
|
53
|
+
deriveRecipientIdHash(publicKey?: Uint8Array): Buffer;
|
|
54
|
+
/**
|
|
55
|
+
* Check if encrypted data is for this wallet (O(1) operation)
|
|
56
|
+
* Enables early termination without attempting expensive crypto decryption
|
|
57
|
+
* @param encryptedBuffer The encrypted data buffer
|
|
58
|
+
* @returns true if we should attempt decryption, false to skip
|
|
59
|
+
*/
|
|
60
|
+
private shouldAttemptDecryption;
|
|
61
|
+
/**
|
|
62
|
+
* Encrypt data with the stored encryption key
|
|
63
|
+
* @param data The data to encrypt
|
|
64
|
+
* @returns The encrypted data as a Buffer
|
|
65
|
+
* @throws Error if the encryption key has not been generated
|
|
66
|
+
*/
|
|
67
|
+
encrypt(data: Buffer | string): Buffer;
|
|
68
|
+
encryptDecryptedDoNotUse(data: Buffer | string): Buffer;
|
|
69
|
+
/**
|
|
70
|
+
* Decrypt data with the stored encryption key
|
|
71
|
+
* @param encryptedData The encrypted data to decrypt
|
|
72
|
+
* @returns The decrypted data as a Buffer, or null if legacy format (no schema version byte)
|
|
73
|
+
* @throws Error if the encryption key has not been generated or if the wrong key is used
|
|
74
|
+
*/
|
|
75
|
+
decrypt(encryptedData: Buffer): Buffer | null;
|
|
76
|
+
/**
|
|
77
|
+
* Decrypt data using the old V1 format (120-bit HMAC with SHA256)
|
|
78
|
+
* @param encryptedData The encrypted data to decrypt
|
|
79
|
+
* @param keypair Optional keypair to derive V1 key for backward compatibility
|
|
80
|
+
* @returns The decrypted data as a Buffer
|
|
81
|
+
*/
|
|
82
|
+
private decryptV1;
|
|
83
|
+
private timingSafeEqual;
|
|
84
|
+
/**
|
|
85
|
+
* Encrypt data using Asymmetric Encryption (X25519 + XSalsa20-Poly1305)
|
|
86
|
+
* @param data The data to encrypt
|
|
87
|
+
* @param recipientPublicKey The recipient's X25519 Public Key
|
|
88
|
+
*/
|
|
89
|
+
encryptAsymmetric(data: Buffer | string, recipientPublicKey: Uint8Array): Buffer;
|
|
90
|
+
/**
|
|
91
|
+
* Decrypt data using Asymmetric Encryption
|
|
92
|
+
* @returns Buffer on success, null if legacy format (no schema version byte) - these are skipped
|
|
93
|
+
*/
|
|
94
|
+
private decryptV3;
|
|
95
|
+
/**
|
|
96
|
+
* Decrypt data using the new V2 format (256-bit Keccak HMAC)
|
|
97
|
+
* @param encryptedData The encrypted data to decrypt
|
|
98
|
+
* @returns The decrypted data as a Buffer, or null if legacy format (no schema version byte) - these are skipped
|
|
99
|
+
*/
|
|
100
|
+
private decryptV2;
|
|
101
|
+
/**
|
|
102
|
+
* Reset the encryption keys (mainly for testing purposes)
|
|
103
|
+
*/
|
|
104
|
+
resetEncryptionKey(): void;
|
|
105
|
+
/**
|
|
106
|
+
* Encrypt a UTXO using a compact pipe-delimited format
|
|
107
|
+
* Always uses V2 encryption format. The UTXO's version property is used only for key derivation.
|
|
108
|
+
* @param utxo The UTXO to encrypt (includes version property)
|
|
109
|
+
* @param recipientEncryptionKey Optional recipient X25519 public key for asymmetric encryption
|
|
110
|
+
* @returns The encrypted UTXO data as a Buffer
|
|
111
|
+
* @throws Error if the V2 encryption key has not been set
|
|
112
|
+
*/
|
|
113
|
+
encryptUtxo(utxo: Utxo, recipientEncryptionKey?: Uint8Array): Buffer;
|
|
114
|
+
encryptUtxoDecryptedDoNotUse(utxo: Utxo): Buffer;
|
|
115
|
+
getEncryptionKeyVersion(encryptedData: Buffer | string): 'v1' | 'v2' | 'v3';
|
|
116
|
+
/**
|
|
117
|
+
* Check if the schema version at byte 9 matches the expected version.
|
|
118
|
+
* Returns null if schema version matches or data is legacy format (no schema version).
|
|
119
|
+
* Returns the found schema version if it doesn't match (for early termination).
|
|
120
|
+
* @param encryptedBuffer The encrypted data buffer
|
|
121
|
+
* @param encryptionVersion The encryption version (v1, v2, v3)
|
|
122
|
+
* @returns null if schema version matches or is legacy, otherwise the mismatched version byte
|
|
123
|
+
*/
|
|
124
|
+
private checkSchemaVersionMismatch;
|
|
125
|
+
/**
|
|
126
|
+
* Decrypt an encrypted UTXO and parse it to a Utxo instance
|
|
127
|
+
* Automatically detects the UTXO version based on the encryption format
|
|
128
|
+
* @param encryptedData The encrypted UTXO data
|
|
129
|
+
* @param keypair The UTXO keypair to use for the decrypted UTXO
|
|
130
|
+
* @param lightWasm Optional LightWasm instance. If not provided, a new one will be created
|
|
131
|
+
* @param walletKeypair Optional wallet keypair for V1 backward compatibility
|
|
132
|
+
* @returns Promise resolving to the decrypted Utxo instance, or null if schema version mismatch
|
|
133
|
+
* @throws Error if the encryption key has not been set or if decryption fails
|
|
134
|
+
*/
|
|
135
|
+
decryptUtxo(encryptedData: Buffer | string, lightWasm?: any): Promise<Utxo | null>;
|
|
136
|
+
getUtxoPrivateKeyWithVersion(version: 'v1' | 'v2'): string;
|
|
137
|
+
deriveUtxoPrivateKey(encryptedData?: Buffer | string): string;
|
|
138
|
+
hasUtxoPrivateKeyWithVersion(version: 'v1' | 'v2'): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Get the cached V1 UTXO private key
|
|
141
|
+
* @returns A private key in hex format that can be used to create a UTXO keypair
|
|
142
|
+
* @throws Error if V1 encryption key has not been set
|
|
143
|
+
*/
|
|
144
|
+
getUtxoPrivateKeyV1(): string;
|
|
145
|
+
/**
|
|
146
|
+
* Get the cached V2 UTXO private key
|
|
147
|
+
* @returns A private key in hex format that can be used to create a UTXO keypair
|
|
148
|
+
* @throws Error if V2 encryption key has not been set
|
|
149
|
+
*/
|
|
150
|
+
getUtxoPrivateKeyV2(): string;
|
|
151
|
+
}
|
|
152
|
+
export declare function serializeProofAndExtData(proof: any, extData: any, isSpl?: boolean): Buffer<ArrayBuffer>;
|