@empereur-rouge/pms-sdk 0.1.0 → 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/README.md CHANGED
@@ -31,9 +31,10 @@ const wallet = PmsWallet.generate();
31
31
  console.log("Mnemonic:", wallet.mnemonic);
32
32
  console.log("Address:", wallet.address);
33
33
 
34
- // 2. Connecter au réseau
34
+ // 2. Connecter au réseau (clé API obligatoire)
35
35
  const client = new PmsClient({
36
- nodeUrl: "https://node.pms.network"
36
+ nodeUrl: "https://node.pms.network",
37
+ apiKey: "pk_live_votre_cle_ici",
37
38
  });
38
39
 
39
40
  // 3. Consulter la balance
@@ -116,6 +117,7 @@ Le client permet d'interagir avec l'API REST des nœuds PMS.
116
117
  ```typescript
117
118
  const client = new PmsClient({
118
119
  nodeUrl: "https://node.pms.network", // URL du nœud principal
120
+ apiKey: "pk_live_votre_cle_ici", // Clé API (obligatoire)
119
121
  seedNodes: [ // Optionnel: nœuds de secours
120
122
  "https://node2.pms.network",
121
123
  "https://node3.pms.network",
@@ -127,6 +129,9 @@ const client = new PmsClient({
127
129
  });
128
130
  ```
129
131
 
132
+ > [!IMPORTANT]
133
+ > La clé API est **obligatoire**. Obtenez-la depuis votre dashboard PMS ou auprès de l'administrateur du réseau.
134
+
130
135
  #### Méthodes de Lecture
131
136
 
132
137
  ```typescript
@@ -480,6 +485,7 @@ Cela améliore :
480
485
  // Désactiver si non souhaité
481
486
  const client = new PmsClient({
482
487
  nodeUrl: "...",
488
+ apiKey: "pk_live_...",
483
489
  enableRacing: false,
484
490
  });
485
491
  ```
package/dist/index.cjs CHANGED
@@ -331,6 +331,11 @@ var PmsClient = class {
331
331
  * @param config.seedNodes - Liste des nœuds de seed
332
332
  */
333
333
  constructor(config) {
334
+ if (!config.apiKey || config.apiKey.trim() === "") {
335
+ throw new Error(
336
+ "PmsClient requires an API key. Get yours at https://dashboard.pms.network or contact your administrator. Usage: new PmsClient({ nodeUrl: '...', apiKey: 'pk_live_...' })"
337
+ );
338
+ }
334
339
  this.config = {
335
340
  ...DEFAULT_CONFIG,
336
341
  seedNodes: config.seedNodes ?? [],
@@ -410,6 +415,68 @@ var PmsClient = class {
410
415
  return res.utxos ?? [];
411
416
  }
412
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
+ // ═══════════════════════════════════════════════════════════════════════
413
480
  // Préparation de Transaction (Server-Side)
414
481
  // ═══════════════════════════════════════════════════════════════════════
415
482
  /**
@@ -1027,6 +1094,9 @@ var PmsClient = class {
1027
1094
  ...init,
1028
1095
  headers: {
1029
1096
  "Content-Type": "application/json",
1097
+ // Injection automatique de la clé API dans chaque requête.
1098
+ // Le serveur PMS vérifie ce header pour autoriser l'accès.
1099
+ "X-API-Key": this.config.apiKey,
1030
1100
  ...init?.headers
1031
1101
  },
1032
1102
  signal
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 */
@@ -473,6 +488,14 @@ interface BalanceInfo {
473
488
  interface PmsClientConfig {
474
489
  /** URL du nœud principal (ex: "https://node.pms.network") */
475
490
  nodeUrl: string;
491
+ /**
492
+ * Clé d'API pour authentifier les requêtes.
493
+ * Obligatoire pour accéder à l'API PMS.
494
+ * Obtenue depuis le dashboard PMS ou fournie par l'administrateur.
495
+ *
496
+ * Exemple: "pk_live_abc123..." ou "pk_test_xyz789..."
497
+ */
498
+ apiKey: string;
476
499
  /** URLs des noeuds seeds (optionnel, pour racing et fallback) */
477
500
  seedNodes?: string[];
478
501
  /** ID du réseau (défaut: "pms-mainnet") */
@@ -594,6 +617,50 @@ declare class PmsClient {
594
617
  * Récupère les UTXOs d'une adresse.
595
618
  */
596
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>;
597
664
  /**
598
665
  * Prépare une transaction de transfert via le serveur.
599
666
  * Le serveur sélectionne les UTXOs et calcule les frais.
@@ -848,4 +915,4 @@ declare function formatAmount(sats: bigint): string;
848
915
  */
849
916
  declare function decryptPayload(encrypted: EncryptedPayload, recipientPrivateKeyHex: string): string;
850
917
 
851
- 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 */
@@ -473,6 +488,14 @@ interface BalanceInfo {
473
488
  interface PmsClientConfig {
474
489
  /** URL du nœud principal (ex: "https://node.pms.network") */
475
490
  nodeUrl: string;
491
+ /**
492
+ * Clé d'API pour authentifier les requêtes.
493
+ * Obligatoire pour accéder à l'API PMS.
494
+ * Obtenue depuis le dashboard PMS ou fournie par l'administrateur.
495
+ *
496
+ * Exemple: "pk_live_abc123..." ou "pk_test_xyz789..."
497
+ */
498
+ apiKey: string;
476
499
  /** URLs des noeuds seeds (optionnel, pour racing et fallback) */
477
500
  seedNodes?: string[];
478
501
  /** ID du réseau (défaut: "pms-mainnet") */
@@ -594,6 +617,50 @@ declare class PmsClient {
594
617
  * Récupère les UTXOs d'une adresse.
595
618
  */
596
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>;
597
664
  /**
598
665
  * Prépare une transaction de transfert via le serveur.
599
666
  * Le serveur sélectionne les UTXOs et calcule les frais.
@@ -848,4 +915,4 @@ declare function formatAmount(sats: bigint): string;
848
915
  */
849
916
  declare function decryptPayload(encrypted: EncryptedPayload, recipientPrivateKeyHex: string): string;
850
917
 
851
- 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
@@ -298,6 +298,11 @@ var PmsClient = class {
298
298
  * @param config.seedNodes - Liste des nœuds de seed
299
299
  */
300
300
  constructor(config) {
301
+ if (!config.apiKey || config.apiKey.trim() === "") {
302
+ throw new Error(
303
+ "PmsClient requires an API key. Get yours at https://dashboard.pms.network or contact your administrator. Usage: new PmsClient({ nodeUrl: '...', apiKey: 'pk_live_...' })"
304
+ );
305
+ }
301
306
  this.config = {
302
307
  ...DEFAULT_CONFIG,
303
308
  seedNodes: config.seedNodes ?? [],
@@ -377,6 +382,68 @@ var PmsClient = class {
377
382
  return res.utxos ?? [];
378
383
  }
379
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
+ // ═══════════════════════════════════════════════════════════════════════
380
447
  // Préparation de Transaction (Server-Side)
381
448
  // ═══════════════════════════════════════════════════════════════════════
382
449
  /**
@@ -994,6 +1061,9 @@ var PmsClient = class {
994
1061
  ...init,
995
1062
  headers: {
996
1063
  "Content-Type": "application/json",
1064
+ // Injection automatique de la clé API dans chaque requête.
1065
+ // Le serveur PMS vérifie ce header pour autoriser l'accès.
1066
+ "X-API-Key": this.config.apiKey,
997
1067
  ...init?.headers
998
1068
  },
999
1069
  signal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empereur-rouge/pms-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
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",