@@ -17,6 +17,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
1717
1818| |
1919| --- |
20+ | [ KeyPairAddress] ( #interface-keypairaddress ) |
2021| [ SetupEnv] ( #interface-setupenv ) |
2122| [ SetupWallet] ( #interface-setupwallet ) |
2223| [ SetupWalletArgs] ( #interface-setupwalletargs ) |
@@ -31,6 +32,21 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
3132
3233---
3334
35+ ##### Interface: KeyPairAddress
36+
37+ A private key and associated public key and address.
38+
39+ ``` ts
40+ export interface KeyPairAddress {
41+ privateKey: PrivateKey ;
42+ publicKey: PublicKey ;
43+ address: string ;
44+ }
45+ ```
46+
47+ Links: [ API] ( #api ) , [ Interfaces] ( #interfaces ) , [ Classes] ( #classes ) , [ Functions] ( #functions ) , [ Types] ( #types ) , [ Variables] ( #variables )
48+
49+ ---
3450##### Interface: SetupEnv
3551
3652` SetupEnv ` provides a starting point for managing secrets that
@@ -561,7 +577,29 @@ export abstract class SetupClient {
561577 console .log (log );
562578 return log ;
563579 }
564- static getEnv(chain : sdk .Chain ): SetupEnv
580+ static getEnv(chain : sdk .Chain ): SetupEnv {
581+ const identityKey = chain === " main"
582+ ? process .env .MY_MAIN_IDENTITY
583+ : process .env .MY_TEST_IDENTITY ;
584+ const identityKey2 = chain === " main"
585+ ? process .env .MY_MAIN_IDENTITY2
586+ : process .env .MY_TEST_IDENTITY2 ;
587+ const DEV_KEYS = process .env .DEV_KEYS || " {}" ;
588+ const mySQLConnection = process .env .MYSQL_CONNECTION || " {}" ;
589+ const taalApiKey = verifyTruthy (chain === " main"
590+ ? process .env .MAIN_TAAL_API_KEY
591+ : process .env .TEST_TAAL_API_KEY , ` .env value for '${chain .toUpperCase ()}_TAAL_API_KEY' is required. ` );
592+ if (! identityKey || ! identityKey2 )
593+ throw new sdk .WERR_INVALID_OPERATION (" .env is not a valid SetupEnv configuration." );
594+ return {
595+ chain ,
596+ identityKey ,
597+ identityKey2 ,
598+ taalApiKey ,
599+ devKeys: JSON .parse (DEV_KEYS ) as Record <string , string >,
600+ mySQLConnection
601+ };
602+ }
565603 static async createWallet(args : SetupWalletArgs ): Promise <SetupWallet > {
566604 const chain = args .env .chain ;
567605 args .rootKeyHex || = args .env .devKeys [args .env .identityKey ];
@@ -602,17 +640,60 @@ export abstract class SetupClient {
602640 };
603641 return r ;
604642 }
605- static async createWalletClient(args : SetupWalletClientArgs ): Promise <SetupWalletClient >
606- static getKeyPair(priv ? : string | PrivateKey ): KeyPairAddress
607- static getLockP2PKH(address : string )
608- static getUnlockP2PKH(priv : PrivateKey , satoshis : number ): sdk .ScriptTemplateUnlock
643+ static async createWalletClient(args : SetupWalletClientArgs ): Promise <SetupWalletClient > {
644+ const wo = await SetupClient .createWallet (args );
645+ if (wo .chain === " main" )
646+ throw new sdk .WERR_INVALID_PARAMETER (" chain" , ` 'test' for now, 'main' is not yet supported. ` );
647+ const endpointUrl = args .endpointUrl || " https://staging-dojo.babbage.systems" ;
648+ const client = new StorageClient (wo .wallet , endpointUrl );
649+ await wo .storage .addWalletStorageProvider (client );
650+ await wo .storage .makeAvailable ();
651+ return {
652+ ... wo ,
653+ endpointUrl
654+ };
655+ }
656+ static getKeyPair(priv ? : string | PrivateKey ): KeyPairAddress {
657+ if (priv === undefined )
658+ priv = PrivateKey .fromRandom ();
659+ else if (typeof priv === " string" )
660+ priv = new PrivateKey (priv , " hex" );
661+ const pub = PublicKey .fromPrivateKey (priv );
662+ const address = pub .toAddress ();
663+ return { privateKey: priv , publicKey: pub , address };
664+ }
665+ static getLockP2PKH(address : string ) {
666+ const p2pkh = new P2PKH ();
667+ const lock = p2pkh .lock (address );
668+ return lock ;
669+ }
670+ static getUnlockP2PKH(priv : PrivateKey , satoshis : number ): sdk .ScriptTemplateUnlock {
671+ const p2pkh = new P2PKH ();
672+ const lock = SetupClient .getLockP2PKH (SetupClient .getKeyPair (priv ).address );
673+ const unlock = p2pkh .unlock (priv , " all" , false , satoshis , lock );
674+ return unlock ;
675+ }
609676 static createP2PKHOutputs(outputs : {
610677 address: string ;
611678 satoshis: number ;
612679 outputDescription? : string ;
613680 basket? : string ;
614681 tags? : string [];
615- }[]): CreateActionOutput []
682+ }[]): CreateActionOutput [] {
683+ const os: CreateActionOutput [] = [];
684+ const count = outputs .length ;
685+ for (let i = 0 ; i < count ; i ++ ) {
686+ const o = outputs [i ];
687+ os .push ({
688+ basket: o .basket ,
689+ tags: o .tags ,
690+ satoshis: o .satoshis ,
691+ lockingScript: SetupClient .getLockP2PKH (o .address ).toHex (),
692+ outputDescription: o .outputDescription || ` p2pkh ${i } `
693+ });
694+ }
695+ return os ;
696+ }
616697 static async createP2PKHOutputsAction(wallet : WalletInterface , outputs : {
617698 address: string ;
618699 satoshis: number ;
@@ -622,12 +703,29 @@ export abstract class SetupClient {
622703 }[], options ? : CreateActionOptions ): Promise <{
623704 cr: CreateActionResult ;
624705 outpoints: string [] | undefined ;
625- }>
626- static async fundWalletFromP2PKHOutpoints(wallet : WalletInterface , outpoints : string [], p2pkhKey : KeyPairAddress , inputBEEF ? : BEEF )
706+ }> {
707+ const os = SetupClient .createP2PKHOutputs (outputs );
708+ const createArgs: CreateActionArgs = {
709+ description: ` createP2PKHOutputs ` ,
710+ outputs: os ,
711+ options: {
712+ ... options ,
713+ randomizeOutputs: false
714+ }
715+ };
716+ const cr = await wallet .createAction (createArgs );
717+ let outpoints: string [] | undefined ;
718+ if (cr .txid ) {
719+ outpoints = os .map ((o , i ) => ` ${cr .txid }.${i } ` );
720+ }
721+ return { cr , outpoints };
722+ }
723+ static async fundWalletFromP2PKHOutpoints(wallet : WalletInterface , outpoints : string [], p2pkhKey : KeyPairAddress , inputBEEF ? : BEEF ) {
724+ }
627725}
628726```
629727
630- See also: [ Chain] ( ./client.md#type-chain ) , [ KeyPairAddress] ( ./setup.md#type -keypairaddress ) , [ Monitor] ( ./monitor.md#class-monitor ) , [ PrivilegedKeyManager] ( ./client.md#class-privilegedkeymanager ) , [ ScriptTemplateUnlock] ( ./client.md#interface-scripttemplateunlock ) , [ Services] ( ./services.md#class-services ) , [ SetupEnv] ( ./setup.md#interface-setupenv ) , [ SetupWallet] ( ./setup.md#interface-setupwallet ) , [ SetupWalletArgs] ( ./setup.md#interface-setupwalletargs ) , [ SetupWalletClient] ( ./setup.md#interface-setupwalletclient ) , [ SetupWalletClientArgs] ( ./setup.md#interface-setupwalletclientargs ) , [ Wallet] ( ./client.md#class-wallet ) , [ WalletStorageManager] ( ./storage.md#class-walletstoragemanager )
728+ See also: [ Chain] ( ./client.md#type-chain ) , [ KeyPairAddress] ( ./setup.md#interface -keypairaddress ) , [ Monitor] ( ./monitor.md#class-monitor ) , [ PrivilegedKeyManager] ( ./client.md#class-privilegedkeymanager ) , [ ScriptTemplateUnlock] ( ./client.md#interface-scripttemplateunlock ) , [ Services] ( ./services.md#class-services ) , [ SetupEnv] ( ./setup.md#interface-setupenv ) , [ SetupWallet] ( ./setup.md#interface-setupwallet ) , [ SetupWalletArgs] ( ./setup.md#interface-setupwalletargs ) , [ SetupWalletClient] ( ./setup.md#interface-setupwalletclient ) , [ SetupWalletClientArgs] ( ./setup.md#interface-setupwalletclientargs ) , [ StorageClient ] ( ./storage.md#class-storageclient ) , [ WERR_INVALID_OPERATION ] ( ./client.md#class-werr_invalid_operation ) , [ WERR_INVALID_PARAMETER ] ( ./client.md#class-werr_invalid_parameter ) , [ Wallet] ( ./client.md#class-wallet ) , [ WalletStorageManager] ( ./storage.md#class-walletstoragemanager ) , [ createAction ] ( ./storage.md#function-createaction ) , [ verifyTruthy ] ( ./client.md#function-verifytruthy )
631729
632730###### Method createWallet
633731
@@ -689,9 +787,31 @@ Returns values for designated `chain`.
689787Access private keys through the ` devKeys ` object: ` devKeys[identityKey] `
690788
691789``` ts
692- static getEnv (chain : sdk .Chain ): SetupEnv
790+ static getEnv (chain : sdk .Chain ): SetupEnv {
791+ const identityKey = chain === " main"
792+ ? process .env .MY_MAIN_IDENTITY
793+ : process .env .MY_TEST_IDENTITY ;
794+ const identityKey2 = chain === " main"
795+ ? process .env .MY_MAIN_IDENTITY2
796+ : process .env .MY_TEST_IDENTITY2 ;
797+ const DEV_KEYS = process .env .DEV_KEYS || " {}" ;
798+ const mySQLConnection = process .env .MYSQL_CONNECTION || " {}" ;
799+ const taalApiKey = verifyTruthy (chain === " main"
800+ ? process .env .MAIN_TAAL_API_KEY
801+ : process .env .TEST_TAAL_API_KEY , ` .env value for '${chain .toUpperCase ()}_TAAL_API_KEY' is required. ` );
802+ if (! identityKey || ! identityKey2 )
803+ throw new sdk .WERR_INVALID_OPERATION (" .env is not a valid SetupEnv configuration." );
804+ return {
805+ chain ,
806+ identityKey ,
807+ identityKey2 ,
808+ taalApiKey ,
809+ devKeys: JSON .parse (DEV_KEYS ) as Record <string , string >,
810+ mySQLConnection
811+ };
812+ }
693813```
694- See also: [ Chain] ( ./client.md#type-chain ) , [ SetupEnv] ( ./setup.md#interface-setupenv )
814+ See also: [ Chain] ( ./client.md#type-chain ) , [ SetupEnv] ( ./setup.md#interface-setupenv ) , [ WERR_INVALID_OPERATION ] ( ./client.md#class-werr_invalid_operation ) , [ verifyTruthy ] ( ./client.md#function-verifytruthy )
695815
696816Returns
697817
@@ -712,7 +832,34 @@ Loading secrets from a .env file is intended only for experimentation and gettin
712832Private keys should never be included directly in your source code.
713833
714834``` ts
715- static makeEnv (): string
835+ static makeEnv (): string {
836+ const testPrivKey1 = PrivateKey .fromRandom ();
837+ const testIdentityKey1 = testPrivKey1 .toPublicKey ().toString ();
838+ const testPrivKey2 = PrivateKey .fromRandom ();
839+ const testIdentityKey2 = testPrivKey2 .toPublicKey ().toString ();
840+ const mainPrivKey1 = PrivateKey .fromRandom ();
841+ const mainIdentityKey1 = mainPrivKey1 .toPublicKey ().toString ();
842+ const mainPrivKey2 = PrivateKey .fromRandom ();
843+ const mainIdentityKey2 = mainPrivKey2 .toPublicKey ().toString ();
844+ const log = `
845+ # Add the following to .env file:
846+ MAIN_TAAL_API_KEY='mainnet_9596de07e92300c6287e4393594ae39c'
847+ TEST_TAAL_API_KEY='testnet_0e6cf72133b43ea2d7861da2a38684e3'
848+ MY_TEST_IDENTITY = '${testIdentityKey1 }'
849+ MY_TEST_IDENTITY2 = '${testIdentityKey2 }'
850+ MY_MAIN_IDENTITY = '${mainIdentityKey1 }'
851+ MY_MAIN_IDENTITY2 = '${mainIdentityKey2 }'
852+ DEV_KEYS = '{
853+ "${testIdentityKey1 }": "${testPrivKey1 .toString ()}",
854+ "${testIdentityKey2 }": "${testPrivKey2 .toString ()}"
855+ "${mainIdentityKey1 }": "${mainPrivKey1 .toString ()}",
856+ "${mainIdentityKey2 }": "${mainPrivKey2 .toString ()}"
857+ }'
858+ MYSQL_CONNECTION='{"port":3306,"host":"127.0.0.1","user":"root","password":"<your_password>","database":"<your_database>", "timezone": "Z"}'
859+ ` ;
860+ console .log (log );
861+ return log ;
862+ }
716863```
717864
718865Links: [ API] ( #api ) , [ Interfaces] ( #interfaces ) , [ Classes] ( #classes ) , [ Functions] ( #functions ) , [ Types] ( #types ) , [ Variables] ( #variables )
@@ -722,19 +869,6 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
722869
723870#### Types
724871
725- ##### Type: KeyPairAddress
726-
727- ``` ts
728- export type KeyPairAddress = {
729- privateKey: PrivateKey ;
730- publicKey: PublicKey ;
731- address: string ;
732- }
733- ` ` `
734-
735- Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
736-
737- ---
738872#### Variables
739873
740874
0 commit comments