@twin.org/wallet-connector-entity-storage 0.0.3-next.5 → 0.9.0-next.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/dist/es/entityStorageWalletConnector.js +1 -1
- package/dist/es/entityStorageWalletConnector.js.map +1 -1
- package/dist/types/entityStorageWalletConnector.d.ts +1 -1
- package/docs/changelog.md +30 -0
- package/docs/reference/classes/EntityStorageWalletConnector.md +1 -1
- package/package.json +10 -10
|
@@ -75,7 +75,7 @@ export class EntityStorageWalletConnector {
|
|
|
75
75
|
/**
|
|
76
76
|
* Create a new wallet.
|
|
77
77
|
* @param identity The identity of the user to access the vault keys.
|
|
78
|
-
* @returns
|
|
78
|
+
* @returns A promise that resolves when the wallet has been created and the mnemonic stored.
|
|
79
79
|
*/
|
|
80
80
|
async create(identity) {
|
|
81
81
|
Guards.stringValue(EntityStorageWalletConnector.CLASS_NAME, "identity", identity);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entityStorageWalletConnector.js","sourceRoot":"","sources":["../../src/entityStorageWalletConnector.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EACN,6BAA6B,EAE7B,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,qBAAqB,EAAwB,MAAM,wBAAwB,CAAC;AACrF,OAAO,EACN,sBAAsB,EAGtB,MAAM,yBAAyB,CAAC;AAKjC;;GAEG;AACH,MAAM,OAAO,4BAA4B;IACxC;;OAEG;IACI,MAAM,CAAU,UAAU,kCAAkD;IAEnF;;OAEG;IACI,MAAM,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AED,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;YAE1D,IAAI,iBAAiB,GAAG,MAAM,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;YAEhF,IAAI,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,EAAE,CAAC;gBACjC,iBAAiB,GAAG;oBACnB,OAAO,EAAE,GAAG;oBACZ,QAAQ,EAAE,EAAE;oBACZ,OAAO,EAAE,WAAW;iBACpB,CAAC;YACH,CAAC;YAED,iBAAiB,CAAC,OAAO,GAAG,CAAC,MAAM,CAAC,iBAAiB,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;YAEpF,MAAM,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAC/D,CAAC;QAED,OAAO,SAAS,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACK,gBAAgB,CAAC,QAAgB;QACxC,OAAO,GAAG,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAC,eAAe,IAAI,4BAA4B,CAAC,6BAA6B,EAAE,CAAC;IACpH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Coerce, GeneralError, Guards, Is } from \"@twin.org/core\";\nimport { Bip39, Bip44, KeyType } from \"@twin.org/crypto\";\nimport { ComparisonOperator, LogicalOperator } from \"@twin.org/entity\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { VaultConnectorFactory, type IVaultConnector } from \"@twin.org/vault-models\";\nimport {\n\tFaucetConnectorFactory,\n\ttype IFaucetConnector,\n\ttype IWalletConnector\n} from \"@twin.org/wallet-models\";\nimport type { WalletAddress } from \"./entities/walletAddress.js\";\nimport type { IEntityStorageWalletConnectorConfig } from \"./models/IEntityStorageWalletConnectorConfig.js\";\nimport type { IEntityStorageWalletConnectorConstructorOptions } from \"./models/IEntityStorageWalletConnectorConstructorOptions.js\";\n\n/**\n * Class for performing wallet operations using in-memory storage.\n */\nexport class EntityStorageWalletConnector implements IWalletConnector {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<EntityStorageWalletConnector>();\n\n\t/**\n\t * The namespace supported by the wallet connector.\n\t */\n\tpublic static readonly NAMESPACE: string = \"entity-storage\";\n\n\t/**\n\t * Default name for the mnemonic secret.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_MNEMONIC_SECRET_NAME: string = \"mnemonic\";\n\n\t/**\n\t * Default coin type.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_COIN_TYPE: number = 9999;\n\n\t/**\n\t * Default network name.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_NETWORK_NAME: string = \"ent\";\n\n\t/**\n\t * The vault for the mnemonic.\n\t * @internal\n\t */\n\tprivate readonly _vaultConnector: IVaultConnector;\n\n\t/**\n\t * The faucet.\n\t * @internal\n\t */\n\tprivate readonly _faucetConnector?: IFaucetConnector;\n\n\t/**\n\t * The entity storage for wallets.\n\t * @internal\n\t */\n\tprivate readonly _walletAddressEntityStorage: IEntityStorageConnector<WalletAddress>;\n\n\t/**\n\t * The configuration to use for tangle operations.\n\t * @internal\n\t */\n\tprivate readonly _config: IEntityStorageWalletConnectorConfig;\n\n\t/**\n\t * Create a new instance of EntityStorageWalletConnector.\n\t * @param options The options for the wallet connector.\n\t */\n\tconstructor(options?: IEntityStorageWalletConnectorConstructorOptions) {\n\t\tthis._vaultConnector = VaultConnectorFactory.get(options?.vaultConnectorType ?? \"vault\");\n\t\tthis._faucetConnector = FaucetConnectorFactory.getIfExists(\n\t\t\toptions?.faucetConnectorType ?? \"faucet\"\n\t\t);\n\t\tthis._walletAddressEntityStorage = EntityStorageConnectorFactory.get(\n\t\t\toptions?.walletAddressEntityStorageType ?? \"wallet-address\"\n\t\t);\n\t\tthis._config = options?.config ?? {};\n\t\tthis._config.coinType ??= EntityStorageWalletConnector._DEFAULT_COIN_TYPE;\n\t\tthis._config.networkName ??= EntityStorageWalletConnector._DEFAULT_NETWORK_NAME;\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn EntityStorageWalletConnector.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create a new wallet.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @returns Nothing.\n\t */\n\tpublic async create(identity: string): Promise<void> {\n\t\tGuards.stringValue(EntityStorageWalletConnector.CLASS_NAME, nameof(identity), identity);\n\n\t\tconst mnemonic = Bip39.randomMnemonic();\n\t\tawait this._vaultConnector.setSecret<string>(this.buildMnemonicKey(identity), mnemonic);\n\t}\n\n\t/**\n\t * Get the addresses for the requested range.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param accountIndex The account index to get the addresses for.\n\t * @param startAddressIndex The start index for the addresses.\n\t * @param count The number of addresses to generate.\n\t * @returns The list of addresses.\n\t */\n\tpublic async getAddresses(\n\t\tidentity: string,\n\t\taccountIndex: number,\n\t\tstartAddressIndex: number,\n\t\tcount: number\n\t): Promise<string[]> {\n\t\tGuards.stringValue(EntityStorageWalletConnector.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.integer(\n\t\t\tEntityStorageWalletConnector.CLASS_NAME,\n\t\t\tnameof(startAddressIndex),\n\t\t\tstartAddressIndex\n\t\t);\n\t\tGuards.integer(EntityStorageWalletConnector.CLASS_NAME, nameof(count), count);\n\n\t\tconst mnemonic = await this._vaultConnector.getSecret<string>(this.buildMnemonicKey(identity));\n\n\t\tconst seed = Bip39.mnemonicToSeed(mnemonic);\n\n\t\tconst keyPairs: string[] = [];\n\n\t\tfor (let i = startAddressIndex; i < startAddressIndex + count; i++) {\n\t\t\tconst addressKeyPair = Bip44.address(\n\t\t\t\tseed,\n\t\t\t\tKeyType.Ed25519,\n\t\t\t\tthis._config.coinType ?? EntityStorageWalletConnector._DEFAULT_COIN_TYPE,\n\t\t\t\taccountIndex,\n\t\t\t\tfalse,\n\t\t\t\ti\n\t\t\t);\n\n\t\t\tkeyPairs.push(addressKeyPair.address);\n\t\t}\n\n\t\treturn keyPairs;\n\t}\n\n\t/**\n\t * Get the balance for an address in a wallet.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param address The hex encoded address.\n\t * @returns The balance of the wallet address.\n\t */\n\tpublic async getBalance(identity: string, address: string): Promise<bigint> {\n\t\tGuards.stringValue(EntityStorageWalletConnector.CLASS_NAME, nameof(address), address);\n\n\t\tconst walletAddress = await this._walletAddressEntityStorage.get(address);\n\n\t\treturn Coerce.bigint(walletAddress?.balance) ?? 0n;\n\t}\n\n\t/**\n\t * Ensure the balance for an address in a wallet.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param address The hex encoded address.\n\t * @param ensureBalance The balance to ensure on the address.\n\t * @param timeoutInSeconds The timeout in seconds to wait for the funding to complete.\n\t * @returns True if the balance has been ensured.\n\t */\n\tpublic async ensureBalance(\n\t\tidentity: string,\n\t\taddress: string,\n\t\tensureBalance: bigint,\n\t\ttimeoutInSeconds?: number\n\t): Promise<boolean> {\n\t\tGuards.stringValue(EntityStorageWalletConnector.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.stringValue(EntityStorageWalletConnector.CLASS_NAME, nameof(address), address);\n\t\tGuards.bigint(EntityStorageWalletConnector.CLASS_NAME, nameof(ensureBalance), ensureBalance);\n\n\t\tif (this._faucetConnector) {\n\t\t\tlet retryCount = 10;\n\t\t\tlet currentBalance = await this.getBalance(identity, address);\n\n\t\t\twhile (currentBalance < ensureBalance && retryCount > 0) {\n\t\t\t\tconst addedBalance = await this._faucetConnector.fundAddress(\n\t\t\t\t\tidentity,\n\t\t\t\t\taddress,\n\t\t\t\t\ttimeoutInSeconds\n\t\t\t\t);\n\t\t\t\tif (addedBalance === 0n) {\n\t\t\t\t\t// The balance has not increased, so return.\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tcurrentBalance += addedBalance;\n\t\t\t\tif (currentBalance < ensureBalance) {\n\t\t\t\t\t// The balance has increased but is still not enough, wait and try again.\n\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, 100));\n\t\t\t\t\tretryCount--;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn currentBalance >= ensureBalance;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Transfer funds to an address.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param addressSource The hex encoded address to send the funds from.\n\t * @param addressDest The hex encoded address to send the funds to.\n\t * @param amount The amount to transfer.\n\t * @returns An identifier for the transfer if there was one.\n\t */\n\tpublic async transfer(\n\t\tidentity: string,\n\t\taddressSource: string,\n\t\taddressDest: string,\n\t\tamount: bigint\n\t): Promise<string | undefined> {\n\t\tGuards.stringValue(EntityStorageWalletConnector.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.stringValue(\n\t\t\tEntityStorageWalletConnector.CLASS_NAME,\n\t\t\tnameof(addressSource),\n\t\t\taddressSource\n\t\t);\n\t\tGuards.stringValue(EntityStorageWalletConnector.CLASS_NAME, nameof(addressDest), addressDest);\n\t\tGuards.bigint(EntityStorageWalletConnector.CLASS_NAME, nameof(amount), amount);\n\n\t\tconst walletAddresses = await this._walletAddressEntityStorage.query({\n\t\t\tlogicalOperator: LogicalOperator.And,\n\t\t\tconditions: [\n\t\t\t\t{\n\t\t\t\t\tproperty: \"identity\",\n\t\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\t\tvalue: identity\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tproperty: \"address\",\n\t\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\t\tvalue: addressSource\n\t\t\t\t}\n\t\t\t]\n\t\t});\n\n\t\tlet walletAddress: WalletAddress | undefined;\n\t\tlet balance = 0n;\n\t\tif (walletAddresses.entities.length > 0) {\n\t\t\twalletAddress = walletAddresses.entities[0] as WalletAddress;\n\t\t\tbalance = BigInt(walletAddress.balance);\n\t\t\twalletAddress.balance = (BigInt(walletAddress.balance) - amount).toString();\n\t\t}\n\n\t\tif (balance < amount) {\n\t\t\tthrow new GeneralError(EntityStorageWalletConnector.CLASS_NAME, \"insufficientFunds\");\n\t\t}\n\n\t\tif (!Is.empty(walletAddress)) {\n\t\t\tawait this._walletAddressEntityStorage.set(walletAddress);\n\n\t\t\tlet destWalletAddress = await this._walletAddressEntityStorage.get(addressDest);\n\n\t\t\tif (Is.empty(destWalletAddress)) {\n\t\t\t\tdestWalletAddress = {\n\t\t\t\t\tbalance: \"0\",\n\t\t\t\t\tidentity: \"\",\n\t\t\t\t\taddress: addressDest\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tdestWalletAddress.balance = (BigInt(destWalletAddress.balance) + amount).toString();\n\n\t\t\tawait this._walletAddressEntityStorage.set(destWalletAddress);\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Build the key name to access the mnemonic in the vault.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @returns The vault key.\n\t * @internal\n\t */\n\tprivate buildMnemonicKey(identity: string): string {\n\t\treturn `${identity}/${this._config.vaultMnemonicId ?? EntityStorageWalletConnector._DEFAULT_MNEMONIC_SECRET_NAME}`;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"entityStorageWalletConnector.js","sourceRoot":"","sources":["../../src/entityStorageWalletConnector.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,eAAe,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,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YACxC,aAAa,CAAC,OAAO,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC7E,CAAC;QAED,IAAI,OAAO,GAAG,MAAM,EAAE,CAAC;YACtB,MAAM,IAAI,YAAY,CAAC,4BAA4B,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC;QACtF,CAAC;QAED,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;YAE1D,IAAI,iBAAiB,GAAG,MAAM,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;YAEhF,IAAI,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,EAAE,CAAC;gBACjC,iBAAiB,GAAG;oBACnB,OAAO,EAAE,GAAG;oBACZ,QAAQ,EAAE,EAAE;oBACZ,OAAO,EAAE,WAAW;iBACpB,CAAC;YACH,CAAC;YAED,iBAAiB,CAAC,OAAO,GAAG,CAAC,MAAM,CAAC,iBAAiB,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;YAEpF,MAAM,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAC/D,CAAC;QAED,OAAO,SAAS,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACK,gBAAgB,CAAC,QAAgB;QACxC,OAAO,GAAG,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAC,eAAe,IAAI,4BAA4B,CAAC,6BAA6B,EAAE,CAAC;IACpH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Coerce, GeneralError, Guards, Is } from \"@twin.org/core\";\nimport { Bip39, Bip44, KeyType } from \"@twin.org/crypto\";\nimport { ComparisonOperator, LogicalOperator } from \"@twin.org/entity\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { VaultConnectorFactory, type IVaultConnector } from \"@twin.org/vault-models\";\nimport {\n\tFaucetConnectorFactory,\n\ttype IFaucetConnector,\n\ttype IWalletConnector\n} from \"@twin.org/wallet-models\";\nimport type { WalletAddress } from \"./entities/walletAddress.js\";\nimport type { IEntityStorageWalletConnectorConfig } from \"./models/IEntityStorageWalletConnectorConfig.js\";\nimport type { IEntityStorageWalletConnectorConstructorOptions } from \"./models/IEntityStorageWalletConnectorConstructorOptions.js\";\n\n/**\n * Class for performing wallet operations using in-memory storage.\n */\nexport class EntityStorageWalletConnector implements IWalletConnector {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<EntityStorageWalletConnector>();\n\n\t/**\n\t * The namespace supported by the wallet connector.\n\t */\n\tpublic static readonly NAMESPACE: string = \"entity-storage\";\n\n\t/**\n\t * Default name for the mnemonic secret.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_MNEMONIC_SECRET_NAME: string = \"mnemonic\";\n\n\t/**\n\t * Default coin type.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_COIN_TYPE: number = 9999;\n\n\t/**\n\t * Default network name.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_NETWORK_NAME: string = \"ent\";\n\n\t/**\n\t * The vault for the mnemonic.\n\t * @internal\n\t */\n\tprivate readonly _vaultConnector: IVaultConnector;\n\n\t/**\n\t * The faucet.\n\t * @internal\n\t */\n\tprivate readonly _faucetConnector?: IFaucetConnector;\n\n\t/**\n\t * The entity storage for wallets.\n\t * @internal\n\t */\n\tprivate readonly _walletAddressEntityStorage: IEntityStorageConnector<WalletAddress>;\n\n\t/**\n\t * The configuration to use for tangle operations.\n\t * @internal\n\t */\n\tprivate readonly _config: IEntityStorageWalletConnectorConfig;\n\n\t/**\n\t * Create a new instance of EntityStorageWalletConnector.\n\t * @param options The options for the wallet connector.\n\t */\n\tconstructor(options?: IEntityStorageWalletConnectorConstructorOptions) {\n\t\tthis._vaultConnector = VaultConnectorFactory.get(options?.vaultConnectorType ?? \"vault\");\n\t\tthis._faucetConnector = FaucetConnectorFactory.getIfExists(\n\t\t\toptions?.faucetConnectorType ?? \"faucet\"\n\t\t);\n\t\tthis._walletAddressEntityStorage = EntityStorageConnectorFactory.get(\n\t\t\toptions?.walletAddressEntityStorageType ?? \"wallet-address\"\n\t\t);\n\t\tthis._config = options?.config ?? {};\n\t\tthis._config.coinType ??= EntityStorageWalletConnector._DEFAULT_COIN_TYPE;\n\t\tthis._config.networkName ??= EntityStorageWalletConnector._DEFAULT_NETWORK_NAME;\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn EntityStorageWalletConnector.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create a new wallet.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @returns A promise that resolves when the wallet has been created and the mnemonic stored.\n\t */\n\tpublic async create(identity: string): Promise<void> {\n\t\tGuards.stringValue(EntityStorageWalletConnector.CLASS_NAME, nameof(identity), identity);\n\n\t\tconst mnemonic = Bip39.randomMnemonic();\n\t\tawait this._vaultConnector.setSecret<string>(this.buildMnemonicKey(identity), mnemonic);\n\t}\n\n\t/**\n\t * Get the addresses for the requested range.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param accountIndex The account index to get the addresses for.\n\t * @param startAddressIndex The start index for the addresses.\n\t * @param count The number of addresses to generate.\n\t * @returns The list of addresses.\n\t */\n\tpublic async getAddresses(\n\t\tidentity: string,\n\t\taccountIndex: number,\n\t\tstartAddressIndex: number,\n\t\tcount: number\n\t): Promise<string[]> {\n\t\tGuards.stringValue(EntityStorageWalletConnector.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.integer(\n\t\t\tEntityStorageWalletConnector.CLASS_NAME,\n\t\t\tnameof(startAddressIndex),\n\t\t\tstartAddressIndex\n\t\t);\n\t\tGuards.integer(EntityStorageWalletConnector.CLASS_NAME, nameof(count), count);\n\n\t\tconst mnemonic = await this._vaultConnector.getSecret<string>(this.buildMnemonicKey(identity));\n\n\t\tconst seed = Bip39.mnemonicToSeed(mnemonic);\n\n\t\tconst keyPairs: string[] = [];\n\n\t\tfor (let i = startAddressIndex; i < startAddressIndex + count; i++) {\n\t\t\tconst addressKeyPair = Bip44.address(\n\t\t\t\tseed,\n\t\t\t\tKeyType.Ed25519,\n\t\t\t\tthis._config.coinType ?? EntityStorageWalletConnector._DEFAULT_COIN_TYPE,\n\t\t\t\taccountIndex,\n\t\t\t\tfalse,\n\t\t\t\ti\n\t\t\t);\n\n\t\t\tkeyPairs.push(addressKeyPair.address);\n\t\t}\n\n\t\treturn keyPairs;\n\t}\n\n\t/**\n\t * Get the balance for an address in a wallet.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param address The hex encoded address.\n\t * @returns The balance of the wallet address.\n\t */\n\tpublic async getBalance(identity: string, address: string): Promise<bigint> {\n\t\tGuards.stringValue(EntityStorageWalletConnector.CLASS_NAME, nameof(address), address);\n\n\t\tconst walletAddress = await this._walletAddressEntityStorage.get(address);\n\n\t\treturn Coerce.bigint(walletAddress?.balance) ?? 0n;\n\t}\n\n\t/**\n\t * Ensure the balance for an address in a wallet.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param address The hex encoded address.\n\t * @param ensureBalance The balance to ensure on the address.\n\t * @param timeoutInSeconds The timeout in seconds to wait for the funding to complete.\n\t * @returns True if the balance has been ensured.\n\t */\n\tpublic async ensureBalance(\n\t\tidentity: string,\n\t\taddress: string,\n\t\tensureBalance: bigint,\n\t\ttimeoutInSeconds?: number\n\t): Promise<boolean> {\n\t\tGuards.stringValue(EntityStorageWalletConnector.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.stringValue(EntityStorageWalletConnector.CLASS_NAME, nameof(address), address);\n\t\tGuards.bigint(EntityStorageWalletConnector.CLASS_NAME, nameof(ensureBalance), ensureBalance);\n\n\t\tif (this._faucetConnector) {\n\t\t\tlet retryCount = 10;\n\t\t\tlet currentBalance = await this.getBalance(identity, address);\n\n\t\t\twhile (currentBalance < ensureBalance && retryCount > 0) {\n\t\t\t\tconst addedBalance = await this._faucetConnector.fundAddress(\n\t\t\t\t\tidentity,\n\t\t\t\t\taddress,\n\t\t\t\t\ttimeoutInSeconds\n\t\t\t\t);\n\t\t\t\tif (addedBalance === 0n) {\n\t\t\t\t\t// The balance has not increased, so return.\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tcurrentBalance += addedBalance;\n\t\t\t\tif (currentBalance < ensureBalance) {\n\t\t\t\t\t// The balance has increased but is still not enough, wait and try again.\n\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, 100));\n\t\t\t\t\tretryCount--;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn currentBalance >= ensureBalance;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Transfer funds to an address.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @param addressSource The hex encoded address to send the funds from.\n\t * @param addressDest The hex encoded address to send the funds to.\n\t * @param amount The amount to transfer.\n\t * @returns An identifier for the transfer if there was one.\n\t */\n\tpublic async transfer(\n\t\tidentity: string,\n\t\taddressSource: string,\n\t\taddressDest: string,\n\t\tamount: bigint\n\t): Promise<string | undefined> {\n\t\tGuards.stringValue(EntityStorageWalletConnector.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.stringValue(\n\t\t\tEntityStorageWalletConnector.CLASS_NAME,\n\t\t\tnameof(addressSource),\n\t\t\taddressSource\n\t\t);\n\t\tGuards.stringValue(EntityStorageWalletConnector.CLASS_NAME, nameof(addressDest), addressDest);\n\t\tGuards.bigint(EntityStorageWalletConnector.CLASS_NAME, nameof(amount), amount);\n\n\t\tconst walletAddresses = await this._walletAddressEntityStorage.query({\n\t\t\tlogicalOperator: LogicalOperator.And,\n\t\t\tconditions: [\n\t\t\t\t{\n\t\t\t\t\tproperty: \"identity\",\n\t\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\t\tvalue: identity\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tproperty: \"address\",\n\t\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\t\tvalue: addressSource\n\t\t\t\t}\n\t\t\t]\n\t\t});\n\n\t\tlet walletAddress: WalletAddress | undefined;\n\t\tlet balance = 0n;\n\t\tif (walletAddresses.entities.length > 0) {\n\t\t\twalletAddress = walletAddresses.entities[0] as WalletAddress;\n\t\t\tbalance = BigInt(walletAddress.balance);\n\t\t\twalletAddress.balance = (BigInt(walletAddress.balance) - amount).toString();\n\t\t}\n\n\t\tif (balance < amount) {\n\t\t\tthrow new GeneralError(EntityStorageWalletConnector.CLASS_NAME, \"insufficientFunds\");\n\t\t}\n\n\t\tif (!Is.empty(walletAddress)) {\n\t\t\tawait this._walletAddressEntityStorage.set(walletAddress);\n\n\t\t\tlet destWalletAddress = await this._walletAddressEntityStorage.get(addressDest);\n\n\t\t\tif (Is.empty(destWalletAddress)) {\n\t\t\t\tdestWalletAddress = {\n\t\t\t\t\tbalance: \"0\",\n\t\t\t\t\tidentity: \"\",\n\t\t\t\t\taddress: addressDest\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tdestWalletAddress.balance = (BigInt(destWalletAddress.balance) + amount).toString();\n\n\t\t\tawait this._walletAddressEntityStorage.set(destWalletAddress);\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Build the key name to access the mnemonic in the vault.\n\t * @param identity The identity of the user to access the vault keys.\n\t * @returns The vault key.\n\t * @internal\n\t */\n\tprivate buildMnemonicKey(identity: string): string {\n\t\treturn `${identity}/${this._config.vaultMnemonicId ?? EntityStorageWalletConnector._DEFAULT_MNEMONIC_SECRET_NAME}`;\n\t}\n}\n"]}
|
|
@@ -25,7 +25,7 @@ export declare class EntityStorageWalletConnector implements IWalletConnector {
|
|
|
25
25
|
/**
|
|
26
26
|
* Create a new wallet.
|
|
27
27
|
* @param identity The identity of the user to access the vault keys.
|
|
28
|
-
* @returns
|
|
28
|
+
* @returns A promise that resolves when the wallet has been created and the mnemonic stored.
|
|
29
29
|
*/
|
|
30
30
|
create(identity: string): Promise<void>;
|
|
31
31
|
/**
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.9.0-next.1](https://github.com/iotaledger/twin-wallet/compare/wallet-connector-entity-storage-v0.9.0-next.0...wallet-connector-entity-storage-v0.9.0-next.1) (2026-06-23)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add context id features ([#46](https://github.com/iotaledger/twin-wallet/issues/46)) ([9389c28](https://github.com/iotaledger/twin-wallet/commit/9389c28084656666d04ed82575cbc8d3fa9f0d88))
|
|
9
|
+
* add validate-locales ([e5200c2](https://github.com/iotaledger/twin-wallet/commit/e5200c279de60592b64eeb64279fa8ed289a677f))
|
|
10
|
+
* eslint migration to flat config ([7068485](https://github.com/iotaledger/twin-wallet/commit/7068485f7c10121b76b6219798fdea4d3e91648a))
|
|
11
|
+
* iota rebased release ([d0c617d](https://github.com/iotaledger/twin-wallet/commit/d0c617d894f3663f7c80f7d53d2da858a0bd64f0))
|
|
12
|
+
* remove bech32 encoding for addresses ([869ef88](https://github.com/iotaledger/twin-wallet/commit/869ef8830eab0bcea6bc748f3bc637fc311e0709))
|
|
13
|
+
* typescript 6 update ([7db75ad](https://github.com/iotaledger/twin-wallet/commit/7db75ade7482bc52f1da01014f0b66fa80d74d51))
|
|
14
|
+
* update dependencies ([a7fc999](https://github.com/iotaledger/twin-wallet/commit/a7fc999be84f1fad40bfa845300b3cf7471cfc7d))
|
|
15
|
+
* update dependencies ([4b47a7d](https://github.com/iotaledger/twin-wallet/commit/4b47a7d900d72d1502d6db54cb391a954818478b))
|
|
16
|
+
* update framework core ([1c8a381](https://github.com/iotaledger/twin-wallet/commit/1c8a381e3c0544803a98db5560d87087fd095c23))
|
|
17
|
+
* use shared store mechanism ([#27](https://github.com/iotaledger/twin-wallet/issues/27)) ([2ba7861](https://github.com/iotaledger/twin-wallet/commit/2ba7861a2a610cf83396a3285c7bbaebe5a31551))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* missing dependency ([6f02070](https://github.com/iotaledger/twin-wallet/commit/6f02070f3ad7d6dcdbbddd952c7d18a47386f15d))
|
|
23
|
+
* use async getStore in tests ([985a549](https://github.com/iotaledger/twin-wallet/commit/985a5493ac79f878d01262f01cdaac7e39196676))
|
|
24
|
+
* use async getStore in tests ([4e6d379](https://github.com/iotaledger/twin-wallet/commit/4e6d3799ef9f3b1f6244ec4204d37a189db54913))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Dependencies
|
|
28
|
+
|
|
29
|
+
* The following workspace dependencies were updated
|
|
30
|
+
* dependencies
|
|
31
|
+
* @twin.org/wallet-models bumped from 0.9.0-next.0 to 0.9.0-next.1
|
|
32
|
+
|
|
3
33
|
## [0.0.3-next.5](https://github.com/iotaledger/twin-wallet/compare/wallet-connector-entity-storage-v0.0.3-next.4...wallet-connector-entity-storage-v0.0.3-next.5) (2026-05-20)
|
|
4
34
|
|
|
5
35
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/wallet-connector-entity-storage",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.9.0-next.1",
|
|
4
4
|
"description": "Implements wallet and faucet connectors backed by entity storage for local and test workflows",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/iotaledger/wallet.git",
|
|
7
|
+
"url": "git+https://github.com/iotaledger/twin-wallet.git",
|
|
8
8
|
"directory": "packages/wallet-connector-entity-storage"
|
|
9
9
|
},
|
|
10
10
|
"author": "martyn.janes@iota.org",
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/core": "next",
|
|
18
|
-
"@twin.org/crypto": "next",
|
|
19
|
-
"@twin.org/entity": "next",
|
|
20
|
-
"@twin.org/entity-storage-models": "next",
|
|
21
|
-
"@twin.org/nameof": "next",
|
|
22
|
-
"@twin.org/vault-models": "next",
|
|
23
|
-
"@twin.org/wallet-models": "0.0
|
|
17
|
+
"@twin.org/core": "0.9.0-next.1",
|
|
18
|
+
"@twin.org/crypto": "0.9.0-next.1",
|
|
19
|
+
"@twin.org/entity": "0.9.0-next.1",
|
|
20
|
+
"@twin.org/entity-storage-models": "0.9.0-next.1",
|
|
21
|
+
"@twin.org/nameof": "0.9.0-next.1",
|
|
22
|
+
"@twin.org/vault-models": "0.9.0-next.1",
|
|
23
|
+
"@twin.org/wallet-models": "0.9.0-next.1"
|
|
24
24
|
},
|
|
25
25
|
"main": "./dist/es/index.js",
|
|
26
26
|
"types": "./dist/types/index.d.ts",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"integration"
|
|
58
58
|
],
|
|
59
59
|
"bugs": {
|
|
60
|
-
"url": "git+https://github.com/iotaledger/wallet/issues"
|
|
60
|
+
"url": "git+https://github.com/iotaledger/twin-wallet/issues"
|
|
61
61
|
},
|
|
62
62
|
"homepage": "https://twindev.org"
|
|
63
63
|
}
|