@empereur-rouge/pms-sdk 0.2.0 → 0.3.1

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/README.md CHANGED
@@ -132,6 +132,43 @@ const client = new PmsClient({
132
132
  > [!IMPORTANT]
133
133
  > La clé API est **obligatoire**. Obtenez-la depuis votre dashboard PMS ou auprès de l'administrateur du réseau.
134
134
 
135
+ #### Wallet (Custodial — Server-Side)
136
+
137
+ Ces méthodes créent/restaurent des wallets **côté serveur**. L'adresse retournée est au format Bech32 (ex: `8e1a...`).
138
+
139
+ ```typescript
140
+ // Créer un nouveau wallet (serveur génère les clés)
141
+ const wallet = await client.createWallet();
142
+ // Réponse (WalletResponse):
143
+ // {
144
+ // address: "8e1ahpltzjauwev6lf0jql...",
145
+ // private_key_b64: "2lM0rVdFXX...",
146
+ // private_key_hex: "da5334ad57455d74...",
147
+ // public_key_hex: "04593037fa9d4f6ea2...",
148
+ // x25519_pub_hex: "266bcd33ab2d20d2...",
149
+ // mnemonic_words: ["gain", "space", "color", ...]
150
+ // }
151
+ ```
152
+
153
+ ```typescript
154
+ // Restaurer un wallet depuis un mnemonic (24 mots BIP39)
155
+ const restored = await client.restoreFromMnemonic(
156
+ "gain space color filter buzz bind side before sauce twist slam history chief patch desk chunk way oblige output turtle purchase scare token rapid"
157
+ );
158
+ console.log(restored.address); // "8e1ahpltzjauwev6lf0jql..."
159
+ ```
160
+
161
+ ```typescript
162
+ // Restaurer un wallet depuis une clé privée hex
163
+ const imported = await client.restoreFromPrivateKey(
164
+ "da5334ad57455d74e5150e4eb06398ce9cf27762b6f29eac7f82f178bee07406"
165
+ );
166
+ console.log(imported.address); // même adresse que ci-dessus
167
+ ```
168
+
169
+ > [!NOTE]
170
+ > Le mnemonic et la clé privée produisent **exactement la même adresse** — la dérivation est déterministe.
171
+
135
172
  #### Méthodes de Lecture
136
173
 
137
174
  ```typescript
@@ -407,6 +444,7 @@ import type {
407
444
  SubmitResponse,
408
445
  BalanceInfo,
409
446
  SupplyInfo,
447
+ WalletResponse,
410
448
 
411
449
  // NFT
412
450
  NftMetadata,
package/dist/index.cjs CHANGED
@@ -415,6 +415,68 @@ var PmsClient = class {
415
415
  return res.utxos ?? [];
416
416
  }
417
417
  // ═══════════════════════════════════════════════════════════════════════
418
+ // Wallet API (Custodial — Server-Side)
419
+ // ═══════════════════════════════════════════════════════════════════════
420
+ /**
421
+ * Crée un nouveau wallet côté serveur (custodial).
422
+ * Le serveur génère le wallet et retourne toutes les clés + adresse Bech32.
423
+ *
424
+ * @returns Wallet complet avec adresse, clés et mnemonic
425
+ *
426
+ * @example
427
+ * ```typescript
428
+ * const wallet = await client.createWallet();
429
+ * console.log(wallet.address); // "8e1a..."
430
+ * console.log(wallet.mnemonic_words); // ["gain", "space", ...]
431
+ * ```
432
+ */
433
+ async createWallet() {
434
+ return this.fetch("/v1/wallet/create", {
435
+ method: "POST",
436
+ body: JSON.stringify({})
437
+ });
438
+ }
439
+ /**
440
+ * Restaure un wallet depuis une phrase mnémonique BIP39 (24 mots).
441
+ *
442
+ * @param mnemonic - 24 mots BIP39 séparés par des espaces
443
+ * @returns Wallet restauré avec adresse, clés et mnemonic
444
+ *
445
+ * @example
446
+ * ```typescript
447
+ * const wallet = await client.restoreFromMnemonic(
448
+ * "gain space color filter buzz bind side before sauce twist slam history chief patch desk chunk way oblige output turtle purchase scare token rapid"
449
+ * );
450
+ * console.log(wallet.address); // "8e1a..."
451
+ * ```
452
+ */
453
+ async restoreFromMnemonic(mnemonic) {
454
+ return this.fetch("/v1/wallet/restore/mnemonic", {
455
+ method: "POST",
456
+ body: JSON.stringify({ mnemonic })
457
+ });
458
+ }
459
+ /**
460
+ * Restaure un wallet depuis une clé privée hexadécimale.
461
+ *
462
+ * @param privateKeyHex - Clé privée hex (64 caractères = 32 bytes)
463
+ * @returns Wallet restauré avec adresse et clés (sans mnemonic)
464
+ *
465
+ * @example
466
+ * ```typescript
467
+ * const wallet = await client.restoreFromPrivateKey(
468
+ * "da5334ad57455d74e5150e4eb06398ce9cf27762b6f29eac7f82f178bee07406"
469
+ * );
470
+ * console.log(wallet.address); // "8e1a..."
471
+ * ```
472
+ */
473
+ async restoreFromPrivateKey(privateKeyHex) {
474
+ return this.fetch("/v1/wallet/restore/private-key", {
475
+ method: "POST",
476
+ body: JSON.stringify({ private_key_hex: privateKeyHex })
477
+ });
478
+ }
479
+ // ═══════════════════════════════════════════════════════════════════════
418
480
  // Préparation de Transaction (Server-Side)
419
481
  // ═══════════════════════════════════════════════════════════════════════
420
482
  /**
package/dist/index.d.cts CHANGED
@@ -460,6 +460,21 @@ interface NftResponse {
460
460
  /** @deprecated Les métadonnées sont maintenant chiffrées dans le bloc source */
461
461
  metadata?: NftMetadata;
462
462
  }
463
+ /** Réponse de création/restauration de wallet (server-side) */
464
+ interface WalletResponse {
465
+ /** Adresse Bech32 du wallet */
466
+ address: string;
467
+ /** Clé privée en base64 */
468
+ private_key_b64: string;
469
+ /** Clé privée en hex (64 chars) */
470
+ private_key_hex: string;
471
+ /** Clé publique secp256k1 non-compressée (hex) */
472
+ public_key_hex: string;
473
+ /** Clé publique X25519 (hex) */
474
+ x25519_pub_hex: string;
475
+ /** Mots mnémoniques (24 mots, absent si restauré depuis clé privée) */
476
+ mnemonic_words?: string[];
477
+ }
463
478
  /** Balance d'une adresse */
464
479
  interface BalanceInfo {
465
480
  /** Adresse */
@@ -602,6 +617,50 @@ declare class PmsClient {
602
617
  * Récupère les UTXOs d'une adresse.
603
618
  */
604
619
  getUtxos(address: string): Promise<Utxo[]>;
620
+ /**
621
+ * Crée un nouveau wallet côté serveur (custodial).
622
+ * Le serveur génère le wallet et retourne toutes les clés + adresse Bech32.
623
+ *
624
+ * @returns Wallet complet avec adresse, clés et mnemonic
625
+ *
626
+ * @example
627
+ * ```typescript
628
+ * const wallet = await client.createWallet();
629
+ * console.log(wallet.address); // "8e1a..."
630
+ * console.log(wallet.mnemonic_words); // ["gain", "space", ...]
631
+ * ```
632
+ */
633
+ createWallet(): Promise<WalletResponse>;
634
+ /**
635
+ * Restaure un wallet depuis une phrase mnémonique BIP39 (24 mots).
636
+ *
637
+ * @param mnemonic - 24 mots BIP39 séparés par des espaces
638
+ * @returns Wallet restauré avec adresse, clés et mnemonic
639
+ *
640
+ * @example
641
+ * ```typescript
642
+ * const wallet = await client.restoreFromMnemonic(
643
+ * "gain space color filter buzz bind side before sauce twist slam history chief patch desk chunk way oblige output turtle purchase scare token rapid"
644
+ * );
645
+ * console.log(wallet.address); // "8e1a..."
646
+ * ```
647
+ */
648
+ restoreFromMnemonic(mnemonic: string): Promise<WalletResponse>;
649
+ /**
650
+ * Restaure un wallet depuis une clé privée hexadécimale.
651
+ *
652
+ * @param privateKeyHex - Clé privée hex (64 caractères = 32 bytes)
653
+ * @returns Wallet restauré avec adresse et clés (sans mnemonic)
654
+ *
655
+ * @example
656
+ * ```typescript
657
+ * const wallet = await client.restoreFromPrivateKey(
658
+ * "da5334ad57455d74e5150e4eb06398ce9cf27762b6f29eac7f82f178bee07406"
659
+ * );
660
+ * console.log(wallet.address); // "8e1a..."
661
+ * ```
662
+ */
663
+ restoreFromPrivateKey(privateKeyHex: string): Promise<WalletResponse>;
605
664
  /**
606
665
  * Prépare une transaction de transfert via le serveur.
607
666
  * Le serveur sélectionne les UTXOs et calcule les frais.
@@ -856,4 +915,4 @@ declare function formatAmount(sats: bigint): string;
856
915
  */
857
916
  declare function decryptPayload(encrypted: EncryptedPayload, recipientPrivateKeyHex: string): string;
858
917
 
859
- export { type BalanceInfo, type Block, type BurnNftResponse, type CoordinatorInfoResponse, type CubeAttributes, type HistoryItem, type MintCubeResponse, type NftMetadata, type NftResponse, PmsClient, type PmsClientConfig, PmsWallet, type PrepareTxRequest, type PrepareTxResponse, type RuntimeConfig, type SubmitResponse, type SupplyInfo, type TokenMetadata, type Utxo, type UtxoDetail, type WalletHistoryResp, decryptPayload, formatAmount, fromHex, isValidMnemonic, parseAmount, toHex };
918
+ export { type BalanceInfo, type Block, type BurnNftResponse, type CoordinatorInfoResponse, type CubeAttributes, type HistoryItem, type MintCubeResponse, type NftMetadata, type NftResponse, PmsClient, type PmsClientConfig, PmsWallet, type PrepareTxRequest, type PrepareTxResponse, type RuntimeConfig, type SubmitResponse, type SupplyInfo, type TokenMetadata, type Utxo, type UtxoDetail, type WalletHistoryResp, type WalletResponse, decryptPayload, formatAmount, fromHex, isValidMnemonic, parseAmount, toHex };
package/dist/index.d.ts CHANGED
@@ -460,6 +460,21 @@ interface NftResponse {
460
460
  /** @deprecated Les métadonnées sont maintenant chiffrées dans le bloc source */
461
461
  metadata?: NftMetadata;
462
462
  }
463
+ /** Réponse de création/restauration de wallet (server-side) */
464
+ interface WalletResponse {
465
+ /** Adresse Bech32 du wallet */
466
+ address: string;
467
+ /** Clé privée en base64 */
468
+ private_key_b64: string;
469
+ /** Clé privée en hex (64 chars) */
470
+ private_key_hex: string;
471
+ /** Clé publique secp256k1 non-compressée (hex) */
472
+ public_key_hex: string;
473
+ /** Clé publique X25519 (hex) */
474
+ x25519_pub_hex: string;
475
+ /** Mots mnémoniques (24 mots, absent si restauré depuis clé privée) */
476
+ mnemonic_words?: string[];
477
+ }
463
478
  /** Balance d'une adresse */
464
479
  interface BalanceInfo {
465
480
  /** Adresse */
@@ -602,6 +617,50 @@ declare class PmsClient {
602
617
  * Récupère les UTXOs d'une adresse.
603
618
  */
604
619
  getUtxos(address: string): Promise<Utxo[]>;
620
+ /**
621
+ * Crée un nouveau wallet côté serveur (custodial).
622
+ * Le serveur génère le wallet et retourne toutes les clés + adresse Bech32.
623
+ *
624
+ * @returns Wallet complet avec adresse, clés et mnemonic
625
+ *
626
+ * @example
627
+ * ```typescript
628
+ * const wallet = await client.createWallet();
629
+ * console.log(wallet.address); // "8e1a..."
630
+ * console.log(wallet.mnemonic_words); // ["gain", "space", ...]
631
+ * ```
632
+ */
633
+ createWallet(): Promise<WalletResponse>;
634
+ /**
635
+ * Restaure un wallet depuis une phrase mnémonique BIP39 (24 mots).
636
+ *
637
+ * @param mnemonic - 24 mots BIP39 séparés par des espaces
638
+ * @returns Wallet restauré avec adresse, clés et mnemonic
639
+ *
640
+ * @example
641
+ * ```typescript
642
+ * const wallet = await client.restoreFromMnemonic(
643
+ * "gain space color filter buzz bind side before sauce twist slam history chief patch desk chunk way oblige output turtle purchase scare token rapid"
644
+ * );
645
+ * console.log(wallet.address); // "8e1a..."
646
+ * ```
647
+ */
648
+ restoreFromMnemonic(mnemonic: string): Promise<WalletResponse>;
649
+ /**
650
+ * Restaure un wallet depuis une clé privée hexadécimale.
651
+ *
652
+ * @param privateKeyHex - Clé privée hex (64 caractères = 32 bytes)
653
+ * @returns Wallet restauré avec adresse et clés (sans mnemonic)
654
+ *
655
+ * @example
656
+ * ```typescript
657
+ * const wallet = await client.restoreFromPrivateKey(
658
+ * "da5334ad57455d74e5150e4eb06398ce9cf27762b6f29eac7f82f178bee07406"
659
+ * );
660
+ * console.log(wallet.address); // "8e1a..."
661
+ * ```
662
+ */
663
+ restoreFromPrivateKey(privateKeyHex: string): Promise<WalletResponse>;
605
664
  /**
606
665
  * Prépare une transaction de transfert via le serveur.
607
666
  * Le serveur sélectionne les UTXOs et calcule les frais.
@@ -856,4 +915,4 @@ declare function formatAmount(sats: bigint): string;
856
915
  */
857
916
  declare function decryptPayload(encrypted: EncryptedPayload, recipientPrivateKeyHex: string): string;
858
917
 
859
- export { type BalanceInfo, type Block, type BurnNftResponse, type CoordinatorInfoResponse, type CubeAttributes, type HistoryItem, type MintCubeResponse, type NftMetadata, type NftResponse, PmsClient, type PmsClientConfig, PmsWallet, type PrepareTxRequest, type PrepareTxResponse, type RuntimeConfig, type SubmitResponse, type SupplyInfo, type TokenMetadata, type Utxo, type UtxoDetail, type WalletHistoryResp, decryptPayload, formatAmount, fromHex, isValidMnemonic, parseAmount, toHex };
918
+ export { type BalanceInfo, type Block, type BurnNftResponse, type CoordinatorInfoResponse, type CubeAttributes, type HistoryItem, type MintCubeResponse, type NftMetadata, type NftResponse, PmsClient, type PmsClientConfig, PmsWallet, type PrepareTxRequest, type PrepareTxResponse, type RuntimeConfig, type SubmitResponse, type SupplyInfo, type TokenMetadata, type Utxo, type UtxoDetail, type WalletHistoryResp, type WalletResponse, decryptPayload, formatAmount, fromHex, isValidMnemonic, parseAmount, toHex };
package/dist/index.js CHANGED
@@ -382,6 +382,68 @@ var PmsClient = class {
382
382
  return res.utxos ?? [];
383
383
  }
384
384
  // ═══════════════════════════════════════════════════════════════════════
385
+ // Wallet API (Custodial — Server-Side)
386
+ // ═══════════════════════════════════════════════════════════════════════
387
+ /**
388
+ * Crée un nouveau wallet côté serveur (custodial).
389
+ * Le serveur génère le wallet et retourne toutes les clés + adresse Bech32.
390
+ *
391
+ * @returns Wallet complet avec adresse, clés et mnemonic
392
+ *
393
+ * @example
394
+ * ```typescript
395
+ * const wallet = await client.createWallet();
396
+ * console.log(wallet.address); // "8e1a..."
397
+ * console.log(wallet.mnemonic_words); // ["gain", "space", ...]
398
+ * ```
399
+ */
400
+ async createWallet() {
401
+ return this.fetch("/v1/wallet/create", {
402
+ method: "POST",
403
+ body: JSON.stringify({})
404
+ });
405
+ }
406
+ /**
407
+ * Restaure un wallet depuis une phrase mnémonique BIP39 (24 mots).
408
+ *
409
+ * @param mnemonic - 24 mots BIP39 séparés par des espaces
410
+ * @returns Wallet restauré avec adresse, clés et mnemonic
411
+ *
412
+ * @example
413
+ * ```typescript
414
+ * const wallet = await client.restoreFromMnemonic(
415
+ * "gain space color filter buzz bind side before sauce twist slam history chief patch desk chunk way oblige output turtle purchase scare token rapid"
416
+ * );
417
+ * console.log(wallet.address); // "8e1a..."
418
+ * ```
419
+ */
420
+ async restoreFromMnemonic(mnemonic) {
421
+ return this.fetch("/v1/wallet/restore/mnemonic", {
422
+ method: "POST",
423
+ body: JSON.stringify({ mnemonic })
424
+ });
425
+ }
426
+ /**
427
+ * Restaure un wallet depuis une clé privée hexadécimale.
428
+ *
429
+ * @param privateKeyHex - Clé privée hex (64 caractères = 32 bytes)
430
+ * @returns Wallet restauré avec adresse et clés (sans mnemonic)
431
+ *
432
+ * @example
433
+ * ```typescript
434
+ * const wallet = await client.restoreFromPrivateKey(
435
+ * "da5334ad57455d74e5150e4eb06398ce9cf27762b6f29eac7f82f178bee07406"
436
+ * );
437
+ * console.log(wallet.address); // "8e1a..."
438
+ * ```
439
+ */
440
+ async restoreFromPrivateKey(privateKeyHex) {
441
+ return this.fetch("/v1/wallet/restore/private-key", {
442
+ method: "POST",
443
+ body: JSON.stringify({ private_key_hex: privateKeyHex })
444
+ });
445
+ }
446
+ // ═══════════════════════════════════════════════════════════════════════
385
447
  // Préparation de Transaction (Server-Side)
386
448
  // ═══════════════════════════════════════════════════════════════════════
387
449
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empereur-rouge/pms-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "TypeScript SDK for PMS (Planetary Monetary System) — wallet management, transactions, NFTs, and DAG interactions",
5
5
  "author": "empereur-rouge",
6
6
  "license": "MIT",