Skip to content

Commit

Permalink
fix: resolve kmd configuration when running on localnet to maintain p…
Browse files Browse the repository at this point in the history
…revious behaviour (#308)

* fix: resolve kmd configuration when running on localnet to maintain previous behaviour
* chore: revert a previous change, as it's no longer needed
  • Loading branch information
neilcampbell authored Aug 19, 2024
1 parent 2919bb4 commit 4fda89c
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 60 deletions.
47 changes: 23 additions & 24 deletions docs/code/classes/types_account_manager.AccountManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const account = await account.dispenserFromEnvironment()

#### Defined in

[src/types/account-manager.ts:410](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L410)
[src/types/account-manager.ts:409](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L409)

___

Expand Down Expand Up @@ -196,15 +196,15 @@ The account

If you have a mnemonic secret loaded into `process.env.MY_ACCOUNT_MNEMONIC` then you can call the following to get that private key loaded into an account object:
```typescript
const account = await account.fromEnvironment('MY_ACCOUNT', algod)
const account = await accountManager.fromEnvironment('MY_ACCOUNT')
```

If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGOs from the default LocalNet dispenser.
If not running against LocalNet then it will use proces.env.MY_ACCOUNT_MNEMONIC as the private key and (if present) process.env.MY_ACCOUNT_SENDER as the sender address.

#### Defined in

[src/types/account-manager.ts:303](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L303)
[src/types/account-manager.ts:302](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L302)

___

Expand Down Expand Up @@ -238,7 +238,7 @@ const defaultDispenserAccount = await account.fromKmd('unencrypted-default-walle

#### Defined in

[src/types/account-manager.ts:339](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L339)
[src/types/account-manager.ts:338](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L338)

___

Expand All @@ -264,13 +264,13 @@ The account
**`Example`**

```typescript
const account = await account.fromMnemonic("mnemonic secret ...")
const rekeyedAccount = await account.fromMnemonic("mnemonic secret ...", "SENDERADDRESS...")
const account = accountManager.fromMnemonic("mnemonic secret ...")
const rekeyedAccount = accountManager.fromMnemonic("mnemonic secret ...", "SENDERADDRESS...")
```

#### Defined in

[src/types/account-manager.ts:255](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L255)
[src/types/account-manager.ts:254](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L254)

___

Expand All @@ -297,16 +297,15 @@ The `TransactionSignerAccount` or throws an error if not found
**`Example`**

```typescript
const account = accountManager.random()
const sender = account.addr
const sender = accountManager.random().addr
// ...
// Returns the `TransactionSignerAccount` for `sender` that has previously been registered
const account = accountManager.getAccount(sender)
```

#### Defined in

[src/types/account-manager.ts:170](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L170)
[src/types/account-manager.ts:169](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L169)

___

Expand Down Expand Up @@ -334,14 +333,14 @@ The account asset holding information
```typescript
const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
const assetId = 123345;
const accountInfo = await accountManager.getAccountAssetInformation(address, assetId);
const accountInfo = await accountManager.getAssetInformation(address, assetId);
```

[Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2accountsaddressassetsasset-id)

#### Defined in

[src/types/account-manager.ts:229](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L229)
[src/types/account-manager.ts:228](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L228)

___

Expand Down Expand Up @@ -374,7 +373,7 @@ const accountInfo = await accountManager.getInformation(address);

#### Defined in

[src/types/account-manager.ts:189](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L189)
[src/types/account-manager.ts:188](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L188)

___

Expand Down Expand Up @@ -431,7 +430,7 @@ const account = await account.localNetDispenser()

#### Defined in

[src/types/account-manager.ts:429](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L429)
[src/types/account-manager.ts:428](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L428)

___

Expand All @@ -457,12 +456,12 @@ A logic signature account wrapper
**`Example`**

```typescript
const account = await account.logicsig(program, [new Uint8Array(3, ...)])
const account = account.logicsig(program, [new Uint8Array(3, ...)])
```

#### Defined in

[src/types/account-manager.ts:377](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L377)
[src/types/account-manager.ts:376](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L376)

___

Expand All @@ -488,13 +487,13 @@ A multisig account wrapper
**`Example`**

```typescript
const account = await account.multisig({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]},
await account.fromEnvironment('ACCOUNT1'))
const account = accountManager.multisig({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]},
[(await accountManager.fromEnvironment('ACCOUNT1')).account])
```

#### Defined in

[src/types/account-manager.ts:362](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L362)
[src/types/account-manager.ts:361](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L361)

___

Expand All @@ -513,12 +512,12 @@ The account
**`Example`**

```typescript
const account = await account.random()
const account = account.random()
```

#### Defined in

[src/types/account-manager.ts:390](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L390)
[src/types/account-manager.ts:389](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L389)

___

Expand All @@ -544,13 +543,13 @@ The account
**`Example`**

```typescript
const account = await account.fromMnemonic("mnemonic secret ...")
const rekeyedAccount = await account.rekeyed(account, "SENDERADDRESS...")
const account = account.fromMnemonic("mnemonic secret ...")
const rekeyedAccount = accountManager.rekeyed(account, "SENDERADDRESS...")
```

#### Defined in

[src/types/account-manager.ts:272](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L272)
[src/types/account-manager.ts:271](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L271)

___

Expand Down
36 changes: 31 additions & 5 deletions docs/code/classes/types_kmd_account_manager.KmdAccountManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ that makes it easier to get and manage accounts using KMD.
### Properties

- [\_clientManager](types_kmd_account_manager.KmdAccountManager.md#_clientmanager)
- [\_kmd](types_kmd_account_manager.KmdAccountManager.md#_kmd)

### Methods

- [getLocalNetDispenserAccount](types_kmd_account_manager.KmdAccountManager.md#getlocalnetdispenseraccount)
- [getOrCreateWalletAccount](types_kmd_account_manager.KmdAccountManager.md#getorcreatewalletaccount)
- [getWalletAccount](types_kmd_account_manager.KmdAccountManager.md#getwalletaccount)
- [kmd](types_kmd_account_manager.KmdAccountManager.md#kmd)

## Constructors

Expand All @@ -43,18 +45,28 @@ Create a new KMD manager.

#### Defined in

[src/types/kmd-account-manager.ts:17](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/kmd-account-manager.ts#L17)
[src/types/kmd-account-manager.ts:18](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/kmd-account-manager.ts#L18)

## Properties

### \_clientManager

`Private` **\_clientManager**: [`ClientManager`](types_client_manager.ClientManager.md)
`Private` **\_clientManager**: `Omit`\<[`ClientManager`](types_client_manager.ClientManager.md), ``"kmd"``\>

#### Defined in

[src/types/kmd-account-manager.ts:11](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/kmd-account-manager.ts#L11)

___

### \_kmd

`Private` `Optional` **\_kmd**: ``null`` \| `default`

#### Defined in

[src/types/kmd-account-manager.ts:12](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/kmd-account-manager.ts#L12)

## Methods

### getLocalNetDispenserAccount
Expand All @@ -77,7 +89,7 @@ const dispenser = await kmdAccountManager.getLocalNetDispenserAccount()

#### Defined in

[src/types/kmd-account-manager.ts:158](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/kmd-account-manager.ts#L158)
[src/types/kmd-account-manager.ts:187](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/kmd-account-manager.ts#L187)

___

Expand Down Expand Up @@ -118,7 +130,7 @@ const existingAccount = await kmdAccountManager.getOrCreateWalletAccount('accoun

#### Defined in

[src/types/kmd-account-manager.ts:108](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/kmd-account-manager.ts#L108)
[src/types/kmd-account-manager.ts:135](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/kmd-account-manager.ts#L135)

___

Expand Down Expand Up @@ -153,4 +165,18 @@ const defaultDispenserAccount = await kmdAccountManager.getWalletAccount(

#### Defined in

[src/types/kmd-account-manager.ts:37](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/kmd-account-manager.ts#L37)
[src/types/kmd-account-manager.ts:62](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/kmd-account-manager.ts#L62)

___

### kmd

**kmd**(): `Promise`\<`default`\>

#### Returns

`Promise`\<`default`\>

#### Defined in

[src/types/kmd-account-manager.ts:27](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/kmd-account-manager.ts#L27)
4 changes: 2 additions & 2 deletions docs/code/modules/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Note: By default this will log the mnemonic of the account.

#### Defined in

[src/testing/account.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/testing/account.ts#L21)
[src/testing/account.ts:20](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/testing/account.ts#L20)

**getTestAccount**(`params`, `algorand`): `Promise`\<`Account`\>

Expand All @@ -202,7 +202,7 @@ The account, with private key loaded

#### Defined in

[src/testing/account.ts:31](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/testing/account.ts#L31)
[src/testing/account.ts:30](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/testing/account.ts#L30)

___

Expand Down
9 changes: 1 addition & 8 deletions src/testing/account.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import algosdk from 'algosdk'
import { AlgorandClient, Config } from '../'
import { ClientManager } from '../types/client-manager'
import { GetTestAccountParams } from '../types/testing'
import Account = algosdk.Account
import Algodv2 = algosdk.Algodv2
Expand Down Expand Up @@ -34,18 +33,12 @@ export async function getTestAccount(
algodOrAlgorandClient: Algodv2 | AlgorandClient,
kmd?: Kmd,
): Promise<Account> {
let kmdClient = kmd
if (!kmdClient) {
const kmdConfig = ClientManager.getConfigFromEnvironmentOrLocalNet().kmdConfig
kmdClient = kmdConfig ? ClientManager.getKmdClient(kmdConfig) : undefined
}

const algorand =
algodOrAlgorandClient instanceof AlgorandClient
? algodOrAlgorandClient
: AlgorandClient.fromClients({
algod: algodOrAlgorandClient,
kmd: kmdClient,
kmd,
})

const account = accountGetter ? await accountGetter(algorand) : algosdk.generateAccount()
Expand Down
25 changes: 12 additions & 13 deletions src/types/account-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ export class AccountManager {
* @param sender The sender address
* @example
* ```typescript
* const account = accountManager.random()
* const sender = account.addr
* const sender = accountManager.random().addr
* // ...
* // Returns the `TransactionSignerAccount` for `sender` that has previously been registered
* const account = accountManager.getAccount(sender)
Expand Down Expand Up @@ -218,7 +217,7 @@ export class AccountManager {
* ```typescript
* const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
* const assetId = 123345;
* const accountInfo = await accountManager.getAccountAssetInformation(address, assetId);
* const accountInfo = await accountManager.getAssetInformation(address, assetId);
* ```
*
* [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2accountsaddressassetsasset-id)
Expand All @@ -244,8 +243,8 @@ export class AccountManager {
*
* @example
* ```typescript
* const account = await account.fromMnemonic("mnemonic secret ...")
* const rekeyedAccount = await account.fromMnemonic("mnemonic secret ...", "SENDERADDRESS...")
* const account = accountManager.fromMnemonic("mnemonic secret ...")
* const rekeyedAccount = accountManager.fromMnemonic("mnemonic secret ...", "SENDERADDRESS...")
* ```
* @param mnemonicSecret The mnemonic secret representing the private key of an account; **Note: Be careful how the mnemonic is handled**,
* never commit it into source control and ideally load it from the environment (ideally via a secret storage service) rather than the file system.
Expand All @@ -262,8 +261,8 @@ export class AccountManager {
*
* @example
* ```typescript
* const account = await account.fromMnemonic("mnemonic secret ...")
* const rekeyedAccount = await account.rekeyed(account, "SENDERADDRESS...")
* const account = account.fromMnemonic("mnemonic secret ...")
* const rekeyedAccount = accountManager.rekeyed(account, "SENDERADDRESS...")
* ```
* @param account The account to use as the signer for this new rekeyed account
* @param sender The sender address to use as the new sender
Expand All @@ -290,7 +289,7 @@ export class AccountManager {
*
* If you have a mnemonic secret loaded into `process.env.MY_ACCOUNT_MNEMONIC` then you can call the following to get that private key loaded into an account object:
* ```typescript
* const account = await account.fromEnvironment('MY_ACCOUNT', algod)
* const account = await accountManager.fromEnvironment('MY_ACCOUNT')
* ```
*
* If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGOs from the default LocalNet dispenser.
Expand Down Expand Up @@ -342,7 +341,7 @@ export class AccountManager {
predicate?: (account: Record<string, any>) => boolean,
sender?: string,
) {
const account = await this.kmd.getWalletAccount(name, predicate, sender)
const account = await this._kmdAccountManager.getWalletAccount(name, predicate, sender)
if (!account) throw new Error(`Unable to find KMD account ${name}${predicate ? ' with predicate' : ''}`)
return this.signerAccount(account.account)
}
Expand All @@ -352,8 +351,8 @@ export class AccountManager {
*
* @example
* ```typescript
* const account = await account.multisig({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]},
* await account.fromEnvironment('ACCOUNT1'))
* const account = accountManager.multisig({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]},
* [(await accountManager.fromEnvironment('ACCOUNT1')).account])
* ```
* @param multisigParams The parameters that define the multisig account
* @param signingAccounts The signers that are currently present
Expand All @@ -368,7 +367,7 @@ export class AccountManager {
*
* @example
* ```typescript
* const account = await account.logicsig(program, [new Uint8Array(3, ...)])
* const account = account.logicsig(program, [new Uint8Array(3, ...)])
* ```
* @param program The bytes that make up the compiled logic signature
* @param args The (binary) arguments to pass into the logic signature
Expand All @@ -383,7 +382,7 @@ export class AccountManager {
*
* @example
* ```typescript
* const account = await account.random()
* const account = account.random()
* ```
* @returns The account
*/
Expand Down
Loading

0 comments on commit 4fda89c

Please sign in to comment.