@btc-vision/cli 1.0.4 → 1.0.6

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.
Files changed (46) hide show
  1. package/package.json +7 -4
  2. package/.gitattributes +0 -2
  3. package/.github/dependabot.yml +0 -9
  4. package/.github/workflows/ci.yml +0 -48
  5. package/.prettierrc.json +0 -12
  6. package/CONTRIBUTING.md +0 -56
  7. package/NOTICE +0 -17
  8. package/SECURITY.md +0 -35
  9. package/eslint.config.js +0 -41
  10. package/gulpfile.js +0 -41
  11. package/src/commands/AcceptCommand.ts +0 -224
  12. package/src/commands/BaseCommand.ts +0 -59
  13. package/src/commands/CompileCommand.ts +0 -195
  14. package/src/commands/ConfigCommand.ts +0 -117
  15. package/src/commands/DeprecateCommand.ts +0 -193
  16. package/src/commands/InfoCommand.ts +0 -293
  17. package/src/commands/InitCommand.ts +0 -541
  18. package/src/commands/InstallCommand.ts +0 -179
  19. package/src/commands/KeygenCommand.ts +0 -157
  20. package/src/commands/ListCommand.ts +0 -169
  21. package/src/commands/LoginCommand.ts +0 -197
  22. package/src/commands/LogoutCommand.ts +0 -76
  23. package/src/commands/PublishCommand.ts +0 -340
  24. package/src/commands/ScopeRegisterCommand.ts +0 -164
  25. package/src/commands/SearchCommand.ts +0 -140
  26. package/src/commands/SignCommand.ts +0 -110
  27. package/src/commands/TransferCommand.ts +0 -363
  28. package/src/commands/UndeprecateCommand.ts +0 -167
  29. package/src/commands/UpdateCommand.ts +0 -200
  30. package/src/commands/VerifyCommand.ts +0 -228
  31. package/src/commands/WhoamiCommand.ts +0 -113
  32. package/src/index.ts +0 -88
  33. package/src/lib/PackageRegistry.abi.json +0 -765
  34. package/src/lib/PackageRegistry.abi.ts +0 -365
  35. package/src/lib/binary.ts +0 -338
  36. package/src/lib/config.ts +0 -265
  37. package/src/lib/credentials.ts +0 -176
  38. package/src/lib/ipfs.ts +0 -382
  39. package/src/lib/manifest.ts +0 -195
  40. package/src/lib/provider.ts +0 -121
  41. package/src/lib/registry.ts +0 -467
  42. package/src/lib/transaction.ts +0 -205
  43. package/src/lib/wallet.ts +0 -262
  44. package/src/types/PackageRegistry.ts +0 -344
  45. package/src/types/index.ts +0 -147
  46. package/tsconfig.json +0 -25
package/src/lib/wallet.ts DELETED
@@ -1,262 +0,0 @@
1
- /**
2
- * Wallet operations for OPNet CLI
3
- *
4
- * Wraps @btc-vision/transaction Mnemonic and Wallet classes for CLI operations
5
- *
6
- * @module lib/wallet
7
- */
8
-
9
- import { Network, networks, Signer } from '@btc-vision/bitcoin';
10
- import { MLDSASecurityLevel, QuantumBIP32Factory, QuantumBIP32Interface } from '@btc-vision/bip32';
11
- import { Address, EcKeyPair, MessageSigner, Mnemonic, Wallet } from '@btc-vision/transaction';
12
- import * as crypto from 'crypto';
13
- import { CLICredentials, CLIMldsaLevel, NetworkName } from '../types/index.js';
14
- import { canSign, loadCredentials } from './credentials.js';
15
- import { ECPairInterface } from 'ecpair';
16
-
17
- /**
18
- * Convert CLI network name to bitcoin-js Network object
19
- */
20
- export function getNetwork(networkName: NetworkName): Network {
21
- switch (networkName) {
22
- case 'mainnet':
23
- return networks.bitcoin;
24
- case 'testnet':
25
- return networks.testnet;
26
- case 'regtest':
27
- return networks.regtest;
28
- }
29
- }
30
-
31
- /**
32
- * Convert CLI MLDSA level to SDK MLDSASecurityLevel enum
33
- */
34
- export function getMLDSASecurityLevel(level: CLIMldsaLevel): MLDSASecurityLevel {
35
- switch (level) {
36
- case 44:
37
- return MLDSASecurityLevel.LEVEL2;
38
- case 65:
39
- return MLDSASecurityLevel.LEVEL3;
40
- case 87:
41
- return MLDSASecurityLevel.LEVEL5;
42
- }
43
- }
44
-
45
- /**
46
- * Wallet wrapper that provides a unified interface for CLI operations
47
- */
48
- export class CLIWallet {
49
- private readonly wallet: Wallet;
50
- private readonly network: Network;
51
- private readonly mldsaLevel: CLIMldsaLevel;
52
-
53
- private constructor(wallet: Wallet, network: Network, mldsaLevel: CLIMldsaLevel) {
54
- this.wallet = wallet;
55
- this.network = network;
56
- this.mldsaLevel = mldsaLevel;
57
- }
58
-
59
- get address(): Address {
60
- return this.wallet.address;
61
- }
62
-
63
- /**
64
- * Get the P2TR (taproot) address
65
- */
66
- get p2trAddress(): string {
67
- return this.wallet.p2tr;
68
- }
69
-
70
- /**
71
- * Get the Bitcoin keypair for classical signing
72
- */
73
- get keypair(): Signer | ECPairInterface | null {
74
- return this.wallet.keypair;
75
- }
76
-
77
- /**
78
- * Get the MLDSA keypair for quantum-resistant signing
79
- */
80
- get mldsaKeypair(): QuantumBIP32Interface {
81
- return this.wallet.mldsaKeypair;
82
- }
83
-
84
- /**
85
- * Get the MLDSA public key
86
- */
87
- get mldsaPublicKey(): Buffer {
88
- return Buffer.from(this.wallet.mldsaKeypair.publicKey);
89
- }
90
-
91
- /**
92
- * Get the MLDSA public key hash (SHA-256)
93
- */
94
- get mldsaPublicKeyHash(): string {
95
- const hash = crypto.createHash('sha256').update(this.mldsaPublicKey).digest();
96
- return hash.toString('hex');
97
- }
98
-
99
- /**
100
- * Get the current MLDSA security level
101
- */
102
- get securityLevel(): CLIMldsaLevel {
103
- return this.mldsaLevel;
104
- }
105
-
106
- /**
107
- * Create a wallet from credentials
108
- *
109
- * @param credentials - The credentials to use
110
- * @returns A CLIWallet instance
111
- */
112
- static fromCredentials(credentials: CLICredentials): CLIWallet {
113
- const network = getNetwork(credentials.network);
114
- const securityLevel = getMLDSASecurityLevel(credentials.mldsaLevel);
115
-
116
- if (credentials.mnemonic) {
117
- // Primary method: derive from mnemonic using UniSat derivation
118
- const mnemonic = new Mnemonic(
119
- credentials.mnemonic,
120
- '', // passphrase
121
- network,
122
- securityLevel,
123
- );
124
- // Use UniSat-compatible derivation with P2TR (Taproot) address type
125
- const wallet = mnemonic.deriveUnisat();
126
- return new CLIWallet(wallet, network, credentials.mldsaLevel);
127
- }
128
-
129
- if (credentials.wif && credentials.mldsaPrivateKey) {
130
- // Advanced method: use WIF + standalone MLDSA key
131
- const wallet = Wallet.fromWif(
132
- credentials.wif,
133
- credentials.mldsaPrivateKey,
134
- network,
135
- securityLevel,
136
- );
137
- return new CLIWallet(wallet, network, credentials.mldsaLevel);
138
- }
139
-
140
- throw new Error('Invalid credentials: requires either mnemonic or both WIF and MLDSA key');
141
- }
142
-
143
- /**
144
- * Load wallet from stored credentials
145
- *
146
- * @returns CLIWallet instance or throws if no valid credentials
147
- */
148
- static load(): CLIWallet {
149
- const credentials = loadCredentials();
150
-
151
- if (!credentials) {
152
- throw new Error('No credentials found. Run `opnet login` to configure your wallet.');
153
- }
154
-
155
- if (!canSign(credentials)) {
156
- throw new Error(
157
- 'Credentials incomplete for signing. Run `opnet login` to reconfigure.',
158
- );
159
- }
160
-
161
- return CLIWallet.fromCredentials(credentials);
162
- }
163
-
164
- /**
165
- * Verify an MLDSA signature using a public key buffer
166
- *
167
- * @param data - The original data that was signed
168
- * @param signature - The signature to verify
169
- * @param publicKey - The MLDSA public key buffer
170
- * @param level - The MLDSA security level
171
- * @returns True if the signature is valid
172
- */
173
- static verifyMLDSA(
174
- data: Buffer,
175
- signature: Buffer,
176
- publicKey: Buffer,
177
- level: CLIMldsaLevel,
178
- ): boolean {
179
- const securityLevel = getMLDSASecurityLevel(level);
180
- // Create a dummy chain code (not needed for verification)
181
- const dummyChainCode = new Uint8Array(32);
182
- // Create a public-key-only keypair for verification
183
- const keypair = QuantumBIP32Factory.fromPublicKey(
184
- publicKey,
185
- dummyChainCode,
186
- networks.bitcoin, // Network doesn't matter for signature verification
187
- securityLevel,
188
- );
189
- // Verify signature directly using the keypair
190
- return keypair.verify(data, signature);
191
- }
192
-
193
- /**
194
- * Sign data using MLDSA
195
- *
196
- * @param data - The data to sign (typically a SHA-256 hash)
197
- * @returns The MLDSA signature
198
- */
199
- signMLDSA(data: Buffer): Buffer {
200
- const result = MessageSigner.signMLDSAMessage(this.wallet.mldsaKeypair, data);
201
- return Buffer.from(result.signature);
202
- }
203
-
204
- /**
205
- * Verify an MLDSA signature using this wallet's keypair
206
- *
207
- * @param data - The original data that was signed
208
- * @param signature - The signature to verify
209
- * @returns True if the signature is valid
210
- */
211
- verifyMLDSA(data: Buffer, signature: Buffer): boolean {
212
- return MessageSigner.verifyMLDSASignature(this.wallet.mldsaKeypair, data, signature);
213
- }
214
- }
215
-
216
- /**
217
- * Generate a standalone MLDSA keypair
218
- *
219
- * @param level - The MLDSA security level
220
- * @returns Object containing privateKey and publicKey buffers
221
- */
222
- export function generateMLDSAKeypair(level: CLIMldsaLevel): {
223
- privateKey: Buffer;
224
- publicKey: Buffer;
225
- } {
226
- const securityLevel = getMLDSASecurityLevel(level);
227
- const keypair = EcKeyPair.generateQuantumKeyPair(securityLevel);
228
-
229
- return {
230
- privateKey: Buffer.from(keypair.privateKey),
231
- publicKey: Buffer.from(keypair.publicKey),
232
- };
233
- }
234
-
235
- /**
236
- * Compute SHA-256 hash of a public key
237
- *
238
- * @param publicKey - The public key buffer
239
- * @returns Hex-encoded SHA-256 hash
240
- */
241
- export function computePublicKeyHash(publicKey: Buffer): string {
242
- return crypto.createHash('sha256').update(publicKey).digest('hex');
243
- }
244
-
245
- /**
246
- * Validate a BIP-39 mnemonic phrase
247
- *
248
- * @param phrase - The mnemonic phrase to validate
249
- * @returns True if the phrase is valid
250
- */
251
- export function validateMnemonic(phrase: string): boolean {
252
- return Mnemonic.validate(phrase);
253
- }
254
-
255
- /**
256
- * Generate a new BIP-39 mnemonic phrase
257
- *
258
- * @returns A new 24-word mnemonic phrase
259
- */
260
- export function generateMnemonic(): string {
261
- return Mnemonic.generatePhrase();
262
- }
@@ -1,344 +0,0 @@
1
- import { Address } from '@btc-vision/transaction';
2
- import { CallResult, IOP_NETContract, OPNetEvent } from 'opnet';
3
-
4
- // ------------------------------------------------------------------
5
- // Event Definitions
6
- // ------------------------------------------------------------------
7
- export type TreasuryAddressChangedEvent = {
8
- readonly previousAddressHash: bigint;
9
- readonly newAddressHash: bigint;
10
- readonly timestamp: bigint;
11
- };
12
- export type ScopePriceChangedEvent = {
13
- readonly oldPrice: bigint;
14
- readonly newPrice: bigint;
15
- readonly timestamp: bigint;
16
- };
17
- export type PackagePriceChangedEvent = {
18
- readonly oldPrice: bigint;
19
- readonly newPrice: bigint;
20
- readonly timestamp: bigint;
21
- };
22
- export type ScopeRegisteredEvent = {
23
- readonly scopeHash: bigint;
24
- readonly owner: Address;
25
- readonly timestamp: bigint;
26
- };
27
- export type ScopeTransferInitiatedEvent = {
28
- readonly scopeHash: bigint;
29
- readonly currentOwner: Address;
30
- readonly newOwner: Address;
31
- readonly timestamp: bigint;
32
- };
33
- export type ScopeTransferCompletedEvent = {
34
- readonly scopeHash: bigint;
35
- readonly previousOwner: Address;
36
- readonly newOwner: Address;
37
- readonly timestamp: bigint;
38
- };
39
- export type ScopeTransferCancelledEvent = {
40
- readonly scopeHash: bigint;
41
- readonly owner: Address;
42
- readonly timestamp: bigint;
43
- };
44
- export type PackageRegisteredEvent = {
45
- readonly packageHash: bigint;
46
- readonly owner: Address;
47
- readonly timestamp: bigint;
48
- };
49
- export type VersionPublishedEvent = {
50
- readonly packageHash: bigint;
51
- readonly versionHash: bigint;
52
- readonly publisher: Address;
53
- readonly checksum: bigint;
54
- readonly timestamp: bigint;
55
- readonly mldsaLevel: number;
56
- readonly pluginType: number;
57
- };
58
- export type VersionDeprecatedEvent = {
59
- readonly packageHash: bigint;
60
- readonly versionHash: bigint;
61
- readonly timestamp: bigint;
62
- };
63
- export type VersionUndeprecatedEvent = {
64
- readonly packageHash: bigint;
65
- readonly versionHash: bigint;
66
- readonly timestamp: bigint;
67
- };
68
- export type PackageTransferInitiatedEvent = {
69
- readonly packageHash: bigint;
70
- readonly currentOwner: Address;
71
- readonly newOwner: Address;
72
- readonly timestamp: bigint;
73
- };
74
- export type PackageTransferCompletedEvent = {
75
- readonly packageHash: bigint;
76
- readonly previousOwner: Address;
77
- readonly newOwner: Address;
78
- readonly timestamp: bigint;
79
- };
80
- export type PackageTransferCancelledEvent = {
81
- readonly packageHash: bigint;
82
- readonly owner: Address;
83
- readonly timestamp: bigint;
84
- };
85
-
86
- // ------------------------------------------------------------------
87
- // Call Results
88
- // ------------------------------------------------------------------
89
-
90
- /**
91
- * @description Represents the result of the setTreasuryAddress function call.
92
- */
93
- export type SetTreasuryAddress = CallResult<{}, OPNetEvent<TreasuryAddressChangedEvent>[]>;
94
-
95
- /**
96
- * @description Represents the result of the setScopePrice function call.
97
- */
98
- export type SetScopePrice = CallResult<{}, OPNetEvent<ScopePriceChangedEvent>[]>;
99
-
100
- /**
101
- * @description Represents the result of the setPackagePrice function call.
102
- */
103
- export type SetPackagePrice = CallResult<{}, OPNetEvent<PackagePriceChangedEvent>[]>;
104
-
105
- /**
106
- * @description Represents the result of the registerScope function call.
107
- */
108
- export type RegisterScope = CallResult<{}, OPNetEvent<ScopeRegisteredEvent>[]>;
109
-
110
- /**
111
- * @description Represents the result of the initiateScopeTransfer function call.
112
- */
113
- export type InitiateScopeTransfer = CallResult<{}, OPNetEvent<ScopeTransferInitiatedEvent>[]>;
114
-
115
- /**
116
- * @description Represents the result of the acceptScopeTransfer function call.
117
- */
118
- export type AcceptScopeTransfer = CallResult<{}, OPNetEvent<ScopeTransferCompletedEvent>[]>;
119
-
120
- /**
121
- * @description Represents the result of the cancelScopeTransfer function call.
122
- */
123
- export type CancelScopeTransfer = CallResult<{}, OPNetEvent<ScopeTransferCancelledEvent>[]>;
124
-
125
- /**
126
- * @description Represents the result of the registerPackage function call.
127
- */
128
- export type RegisterPackage = CallResult<{}, OPNetEvent<PackageRegisteredEvent>[]>;
129
-
130
- /**
131
- * @description Represents the result of the publishVersion function call.
132
- */
133
- export type PublishVersion = CallResult<{}, OPNetEvent<VersionPublishedEvent>[]>;
134
-
135
- /**
136
- * @description Represents the result of the deprecateVersion function call.
137
- */
138
- export type DeprecateVersion = CallResult<{}, OPNetEvent<VersionDeprecatedEvent>[]>;
139
-
140
- /**
141
- * @description Represents the result of the undeprecateVersion function call.
142
- */
143
- export type UndeprecateVersion = CallResult<{}, OPNetEvent<VersionUndeprecatedEvent>[]>;
144
-
145
- /**
146
- * @description Represents the result of the initiateTransfer function call.
147
- */
148
- export type InitiateTransfer = CallResult<{}, OPNetEvent<PackageTransferInitiatedEvent>[]>;
149
-
150
- /**
151
- * @description Represents the result of the acceptTransfer function call.
152
- */
153
- export type AcceptTransfer = CallResult<{}, OPNetEvent<PackageTransferCompletedEvent>[]>;
154
-
155
- /**
156
- * @description Represents the result of the cancelTransfer function call.
157
- */
158
- export type CancelTransfer = CallResult<{}, OPNetEvent<PackageTransferCancelledEvent>[]>;
159
-
160
- /**
161
- * @description Represents the result of the getScope function call.
162
- */
163
- export type GetScope = CallResult<
164
- {
165
- exists: boolean;
166
- owner: Address;
167
- createdAt: bigint;
168
- },
169
- OPNetEvent<never>[]
170
- >;
171
-
172
- /**
173
- * @description Represents the result of the getScopeOwner function call.
174
- */
175
- export type GetScopeOwner = CallResult<
176
- {
177
- owner: Address;
178
- },
179
- OPNetEvent<never>[]
180
- >;
181
-
182
- /**
183
- * @description Represents the result of the getPackage function call.
184
- */
185
- export type GetPackage = CallResult<
186
- {
187
- exists: boolean;
188
- owner: Address;
189
- createdAt: bigint;
190
- versionCount: bigint;
191
- latestVersion: string;
192
- },
193
- OPNetEvent<never>[]
194
- >;
195
-
196
- /**
197
- * @description Represents the result of the getOwner function call.
198
- */
199
- export type GetOwner = CallResult<
200
- {
201
- owner: Address;
202
- },
203
- OPNetEvent<never>[]
204
- >;
205
-
206
- /**
207
- * @description Represents the result of the getVersion function call.
208
- */
209
- export type GetVersion = CallResult<
210
- {
211
- exists: boolean;
212
- ipfsCid: string;
213
- checksum: Uint8Array;
214
- sigHash: Uint8Array;
215
- mldsaLevel: number;
216
- opnetVersionRange: string;
217
- pluginType: number;
218
- permissionsHash: Uint8Array;
219
- depsHash: Uint8Array;
220
- publisher: Address;
221
- publishedAt: bigint;
222
- deprecated: boolean;
223
- },
224
- OPNetEvent<never>[]
225
- >;
226
-
227
- /**
228
- * @description Represents the result of the isDeprecated function call.
229
- */
230
- export type IsDeprecated = CallResult<
231
- {
232
- deprecated: boolean;
233
- },
234
- OPNetEvent<never>[]
235
- >;
236
-
237
- /**
238
- * @description Represents the result of the isImmutable function call.
239
- */
240
- export type IsImmutable = CallResult<
241
- {
242
- immutable: boolean;
243
- },
244
- OPNetEvent<never>[]
245
- >;
246
-
247
- /**
248
- * @description Represents the result of the getPendingTransfer function call.
249
- */
250
- export type GetPendingTransfer = CallResult<
251
- {
252
- pendingOwner: Address;
253
- initiatedAt: bigint;
254
- },
255
- OPNetEvent<never>[]
256
- >;
257
-
258
- /**
259
- * @description Represents the result of the getPendingScopeTransfer function call.
260
- */
261
- export type GetPendingScopeTransfer = CallResult<
262
- {
263
- pendingOwner: Address;
264
- initiatedAt: bigint;
265
- },
266
- OPNetEvent<never>[]
267
- >;
268
-
269
- /**
270
- * @description Represents the result of the getTreasuryAddress function call.
271
- */
272
- export type GetTreasuryAddress = CallResult<
273
- {
274
- treasuryAddress: string;
275
- },
276
- OPNetEvent<never>[]
277
- >;
278
-
279
- /**
280
- * @description Represents the result of the getScopePrice function call.
281
- */
282
- export type GetScopePrice = CallResult<
283
- {
284
- priceSats: bigint;
285
- },
286
- OPNetEvent<never>[]
287
- >;
288
-
289
- /**
290
- * @description Represents the result of the getPackagePrice function call.
291
- */
292
- export type GetPackagePrice = CallResult<
293
- {
294
- priceSats: bigint;
295
- },
296
- OPNetEvent<never>[]
297
- >;
298
-
299
- // ------------------------------------------------------------------
300
- // IPackageRegistry
301
- // ------------------------------------------------------------------
302
- export interface IPackageRegistry extends IOP_NETContract {
303
- setTreasuryAddress(treasuryAddress: string): Promise<SetTreasuryAddress>;
304
- setScopePrice(priceSats: bigint): Promise<SetScopePrice>;
305
- setPackagePrice(priceSats: bigint): Promise<SetPackagePrice>;
306
- registerScope(scopeName: string): Promise<RegisterScope>;
307
- initiateScopeTransfer(scopeName: string, newOwner: Address): Promise<InitiateScopeTransfer>;
308
- acceptScopeTransfer(scopeName: string): Promise<AcceptScopeTransfer>;
309
- cancelScopeTransfer(scopeName: string): Promise<CancelScopeTransfer>;
310
- registerPackage(packageName: string): Promise<RegisterPackage>;
311
- publishVersion(
312
- packageName: string,
313
- version: string,
314
- ipfsCid: string,
315
- checksum: Uint8Array,
316
- signature: Uint8Array,
317
- mldsaLevel: number,
318
- opnetVersionRange: string,
319
- pluginType: number,
320
- permissionsHash: Uint8Array,
321
- dependencies: Uint8Array,
322
- ): Promise<PublishVersion>;
323
- deprecateVersion(
324
- packageName: string,
325
- version: string,
326
- reason: string,
327
- ): Promise<DeprecateVersion>;
328
- undeprecateVersion(packageName: string, version: string): Promise<UndeprecateVersion>;
329
- initiateTransfer(packageName: string, newOwner: Address): Promise<InitiateTransfer>;
330
- acceptTransfer(packageName: string): Promise<AcceptTransfer>;
331
- cancelTransfer(packageName: string): Promise<CancelTransfer>;
332
- getScope(scopeName: string): Promise<GetScope>;
333
- getScopeOwner(scopeName: string): Promise<GetScopeOwner>;
334
- getPackage(packageName: string): Promise<GetPackage>;
335
- getOwner(packageName: string): Promise<GetOwner>;
336
- getVersion(packageName: string, version: string): Promise<GetVersion>;
337
- isDeprecated(packageName: string, version: string): Promise<IsDeprecated>;
338
- isImmutable(packageName: string, version: string): Promise<IsImmutable>;
339
- getPendingTransfer(packageName: string): Promise<GetPendingTransfer>;
340
- getPendingScopeTransfer(scopeName: string): Promise<GetPendingScopeTransfer>;
341
- getTreasuryAddress(): Promise<GetTreasuryAddress>;
342
- getScopePrice(): Promise<GetScopePrice>;
343
- getPackagePrice(): Promise<GetPackagePrice>;
344
- }