@neuraiproject/neurai-sign-esp32 0.1.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.
@@ -0,0 +1,235 @@
1
+ import { Network } from "bitcoinjs-lib";
2
+ /**
3
+ * Types for neurai-sign-esp32
4
+ */
5
+ export interface IUTXO {
6
+ /** Transaction ID */
7
+ txid: string;
8
+ /** Output index in the transaction */
9
+ vout: number;
10
+ /** ScriptPubKey hex */
11
+ scriptPubKey: string;
12
+ /** Value in satoshis */
13
+ satoshis: number;
14
+ /** Full raw transaction hex (required for P2PKH nonWitnessUtxo) */
15
+ rawTxHex: string;
16
+ }
17
+ export interface ITxOutput {
18
+ /** Destination address */
19
+ address: string;
20
+ /** Value in satoshis */
21
+ value: number;
22
+ }
23
+ export interface IBuildPSBTOptions {
24
+ /** Network: 'xna' | 'xna-test' | 'xna-legacy' | 'xna-legacy-test' */
25
+ network: NetworkType;
26
+ /** UTXOs to spend */
27
+ utxos: IUTXO[];
28
+ /** Destination outputs (excluding change) */
29
+ outputs: ITxOutput[];
30
+ /** Change address (device address) */
31
+ changeAddress: string;
32
+ /** Compressed public key hex (from device) */
33
+ pubkey: string;
34
+ /** Master fingerprint hex (from device info) */
35
+ masterFingerprint: string;
36
+ /** BIP44 derivation path, e.g. "m/44'/1900'/0'/0/0" */
37
+ derivationPath: string;
38
+ /** Fee rate in satoshis per byte (default: 1024) */
39
+ feeRate?: number;
40
+ }
41
+ export interface IDeviceInfo {
42
+ status: string;
43
+ device: string;
44
+ version: string;
45
+ chip: string;
46
+ network: string;
47
+ coin_type: number;
48
+ master_fingerprint: string;
49
+ path: string;
50
+ address: string;
51
+ pubkey: string;
52
+ }
53
+ export interface IAddressResponse {
54
+ status: string;
55
+ address: string;
56
+ pubkey: string;
57
+ path: string;
58
+ }
59
+ export interface IBip32PubkeyResponse {
60
+ status: string;
61
+ bip32_pubkey: string;
62
+ master_fingerprint: string;
63
+ path: string;
64
+ }
65
+ export interface ISignPsbtResponse {
66
+ status: string;
67
+ psbt: string;
68
+ signed_inputs: number;
69
+ }
70
+ export interface IErrorResponse {
71
+ status: "error";
72
+ message: string;
73
+ }
74
+ interface IProcessingResponse {
75
+ status: "processing";
76
+ stage: string;
77
+ }
78
+ type DeviceResponse = IDeviceInfo | IAddressResponse | IBip32PubkeyResponse | ISignPsbtResponse | IErrorResponse | IProcessingResponse;
79
+ export interface ISerialOptions {
80
+ /** Baud rate (default: 115200) */
81
+ baudRate?: number;
82
+ /** USB vendor/product filters for port selection */
83
+ filters?: SerialPortFilter[];
84
+ }
85
+ export type NetworkType = "xna" | "xna-test" | "xna-legacy" | "xna-legacy-test";
86
+ export interface ISignResult {
87
+ /** Signed PSBT in base64 */
88
+ signedPsbtBase64: string;
89
+ /** Finalized raw transaction hex, ready to broadcast */
90
+ txHex: string;
91
+ /** Transaction ID */
92
+ txId: string;
93
+ /** Number of inputs signed by the device */
94
+ signedInputs: number;
95
+ }
96
+ export class SerialConnection {
97
+ constructor(options?: ISerialOptions);
98
+ /**
99
+ * Check if Web Serial API is available.
100
+ */
101
+ static isSupported(): boolean;
102
+ /**
103
+ * Open a serial connection to the ESP32.
104
+ * Triggers browser port selection dialog.
105
+ */
106
+ open(): Promise<void>;
107
+ /**
108
+ * Close the serial connection.
109
+ */
110
+ close(): Promise<void>;
111
+ /**
112
+ * Whether the serial port is currently connected.
113
+ */
114
+ get connected(): boolean;
115
+ /**
116
+ * Send a JSON command to the device and wait for a JSON response.
117
+ *
118
+ * @param command - The command object (e.g. { action: "info" })
119
+ * @param timeoutMs - Response timeout in milliseconds (default: 65000 for sign operations)
120
+ * @returns The parsed device response
121
+ */
122
+ sendCommand(command: Record<string, unknown>, timeoutMs?: number): Promise<DeviceResponse>;
123
+ /**
124
+ * Send a command and wait, skipping intermediate "processing" status messages.
125
+ * Useful for sign_psbt which sends a processing ACK before the actual response.
126
+ */
127
+ sendCommandFinal(command: Record<string, unknown>, timeoutMs?: number): Promise<DeviceResponse>;
128
+ }
129
+ export const neuraiMainnet: Network;
130
+ export const neuraiTestnet: Network;
131
+ export const neuraiLegacyMainnet: Network;
132
+ export const neuraiLegacyTestnet: Network;
133
+ /**
134
+ * Get the bitcoinjs-lib Network object for a given Neurai network type.
135
+ */
136
+ export function getNetwork(network: NetworkType): Network;
137
+ /**
138
+ * Build an unsigned PSBT for Neurai P2PKH, ready to send to the ESP32.
139
+ *
140
+ * @returns Base64-encoded PSBT string
141
+ */
142
+ export function buildPSBT(options: IBuildPSBTOptions): string;
143
+ /**
144
+ * Finalize a signed PSBT and extract the raw transaction.
145
+ *
146
+ * Call this after receiving the signed PSBT back from the ESP32.
147
+ *
148
+ * @param signedPsbtBase64 - Base64-encoded signed PSBT from the device
149
+ * @param network - Network type
150
+ * @returns Object with txHex (raw tx for broadcast) and txId
151
+ */
152
+ export function finalizePSBT(signedPsbtBase64: string, network: "xna" | "xna-test" | "xna-legacy" | "xna-legacy-test"): {
153
+ txHex: string;
154
+ txId: string;
155
+ };
156
+ /**
157
+ * Validate that a PSBT base64 string is parseable.
158
+ */
159
+ export function validatePSBT(psbtBase64: string, network: "xna" | "xna-test" | "xna-legacy" | "xna-legacy-test"): boolean;
160
+ export class NeuraiESP32 {
161
+ constructor(options?: ISerialOptions);
162
+ /**
163
+ * Check if Web Serial API is supported in this browser.
164
+ */
165
+ static isSupported(): boolean;
166
+ /**
167
+ * Whether the device is currently connected.
168
+ */
169
+ get connected(): boolean;
170
+ /**
171
+ * Cached device info from the last getInfo() call.
172
+ */
173
+ get info(): IDeviceInfo | null;
174
+ /**
175
+ * Connect to the ESP32 hardware wallet.
176
+ * Opens the browser port selection dialog.
177
+ */
178
+ connect(): Promise<void>;
179
+ /**
180
+ * Disconnect from the device.
181
+ */
182
+ disconnect(): Promise<void>;
183
+ /**
184
+ * Get device information (no user confirmation needed).
185
+ * Returns device name, version, network, address, pubkey, etc.
186
+ */
187
+ getInfo(): Promise<IDeviceInfo>;
188
+ /**
189
+ * Request the device address and public key.
190
+ * Requires user physical confirmation on the device (30s timeout).
191
+ */
192
+ getAddress(): Promise<IAddressResponse>;
193
+ /**
194
+ * Request the BIP32 account extended public key (xpub).
195
+ * Requires user physical confirmation on the device (30s timeout).
196
+ */
197
+ getBip32Pubkey(): Promise<IBip32PubkeyResponse>;
198
+ /**
199
+ * Send a raw PSBT (base64) to the device for signing.
200
+ * Requires user physical confirmation on the device (60s timeout).
201
+ *
202
+ * Use this if you build the PSBT yourself.
203
+ */
204
+ signPsbt(psbtBase64: string): Promise<ISignPsbtResponse>;
205
+ /**
206
+ * Build, sign, and finalize a transaction in one call.
207
+ *
208
+ * This is the main method for sending XNA. It:
209
+ * 1. Builds an unsigned PSBT from the provided UTXOs and outputs
210
+ * 2. Sends it to the ESP32 for signing (user confirms on device)
211
+ * 3. Finalizes the signed PSBT and extracts the raw transaction
212
+ *
213
+ * @param options.network - Network type (default: uses device info)
214
+ * @param options.utxos - UTXOs to spend (must include rawTxHex)
215
+ * @param options.outputs - Destination outputs [{address, value}]
216
+ * @param options.changeAddress - Address for change (typically device address)
217
+ * @param options.pubkey - Compressed public key hex (from getAddress)
218
+ * @param options.masterFingerprint - From getInfo().master_fingerprint
219
+ * @param options.derivationPath - From getAddress().path
220
+ * @param options.feeRate - Fee rate in sat/byte (default: 1024)
221
+ * @returns ISignResult with txHex ready to broadcast
222
+ */
223
+ signTransaction(options: {
224
+ network?: NetworkType;
225
+ utxos: IUTXO[];
226
+ outputs: ITxOutput[];
227
+ changeAddress: string;
228
+ pubkey?: string;
229
+ masterFingerprint?: string;
230
+ derivationPath?: string;
231
+ feeRate?: number;
232
+ }): Promise<ISignResult>;
233
+ }
234
+
235
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"mappings":";AAAA;;GAEG;AAIH;IACE,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,uBAAuB;IACvB,YAAY,EAAE,MAAM,CA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QACf,OAAO,EAAE,SAAS,EAAE,CAAC;QACrB,aAAa,EAAE,MAAM,CAAC;QACtB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,WAAW,CAAC;CAoFzB","sources":["src/src/types.ts","src/src/serial.ts","src/src/networks.ts","src/src/psbt.ts","src/src/NeuraiESP32.ts","src/src/index.ts","src/index.ts"],"sourcesContent":[null,null,null,null,null,null,"/**\n * @neuraiproject/neurai-sign-esp32\n *\n * Library for creating and signing Neurai (XNA) PSBTs\n * via ESP32 hardware wallet (NeuraiHW).\n */\n\n// Main class\nexport { NeuraiESP32 } from \"./NeuraiESP32.js\";\n\n// PSBT utilities\nexport { buildPSBT, finalizePSBT, validatePSBT } from \"./psbt.js\";\n\n// Serial connection (for advanced use)\nexport { SerialConnection } from \"./serial.js\";\n\n// Network configs\nexport {\n getNetwork,\n neuraiMainnet,\n neuraiTestnet,\n neuraiLegacyMainnet,\n neuraiLegacyTestnet,\n} from \"./networks.js\";\n\n// Types\nexport type {\n IUTXO,\n ITxOutput,\n IBuildPSBTOptions,\n IDeviceInfo,\n IAddressResponse,\n IBip32PubkeyResponse,\n ISignPsbtResponse,\n IErrorResponse,\n ISerialOptions,\n ISignResult,\n NetworkType,\n} from \"./types.js\";\n"],"names":[],"version":3,"file":"index.d.ts.map"}