Documentation / @cashconnect-js/templates-dev / wallet/wallet-p2pkh
WalletP2PKHGenesisData
type WalletP2PKHGenesisData = object;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:37
Properties
type
type: "WalletP2PKH";Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:38
privateKey
privateKey: string;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:39
WalletP2PKHFactory()
type WalletP2PKHFactory<T> = (dependencies, genesisData) => Promise<T>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:480
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends WalletP2PKH | WalletP2PKH |
Parameters
| Parameter | Type |
|---|---|
dependencies | WalletDependencies |
genesisData | WalletP2PKHGenesisData |
Returns
Promise<T>
WalletP2PKH
Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:52
Example
// Instantiate P2PKH Wallet.
const walletP2PKH = WalletP2PKH.fromWIF('someWif');
// Start monitoring the balance.
await walletP2PKH.startMonitoring();Extends
Constructors
Constructor
new WalletP2PKH(dependencies, genesisData): WalletP2PKH;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:138
Parameters
| Parameter | Type |
|---|---|
dependencies | Required<WalletDependencies> |
genesisData | Omit<WalletP2PKHGenesisData, "type"> |
Returns
Overrides
Methods
from()
static from<T>(
this,
deps,
genesisData): Promise<InstanceType<T>>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:53
Type Parameters
| Type Parameter |
|---|
T extends typeof WalletP2PKH |
Parameters
| Parameter | Type |
|---|---|
this | T |
deps | WalletDependencies |
genesisData | Omit<WalletP2PKHGenesisData, "type"> |
Returns
Promise<InstanceType<T>>
fromBytes()
static fromBytes<T>(
this,
services,
privateKeyBytes): Promise<InstanceType<T>>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:70
Type Parameters
| Type Parameter |
|---|
T extends typeof WalletP2PKH |
Parameters
| Parameter | Type |
|---|---|
this | T |
services | WalletDependencies |
privateKeyBytes | Uint8Array |
Returns
Promise<InstanceType<T>>
fromHex()
static fromHex<T>(
this,
services,
privateKeyHex): Promise<InstanceType<T>>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:84
Type Parameters
| Type Parameter |
|---|
T extends typeof WalletP2PKH |
Parameters
| Parameter | Type |
|---|---|
this | T |
services | WalletDependencies |
privateKeyHex | string |
Returns
Promise<InstanceType<T>>
fromWIF()
static fromWIF<T>(
this,
services,
privateKeyWif): Promise<InstanceType<T>>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:98
Type Parameters
| Type Parameter |
|---|
T extends typeof WalletP2PKH |
Parameters
| Parameter | Type |
|---|---|
this | T |
services | WalletDependencies |
privateKeyWif | string |
Returns
Promise<InstanceType<T>>
generateRandom()
static generateRandom<T>(this, services): Promise<InstanceType<T>>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:112
Type Parameters
| Type Parameter |
|---|
T extends typeof WalletP2PKH |
Parameters
| Parameter | Type |
|---|---|
this | T |
services | WalletDependencies |
Returns
Promise<InstanceType<T>>
deriveKey()
static deriveKey(genesisData, keyName): Uint8Array<ArrayBufferLike>;Defined in: packages/templates-dev/src/wallet/base-wallet.ts:51
Derive a key to use based on the given Genesis Data.
Parameters
| Parameter | Type |
|---|---|
genesisData | WalletGenesisData |
keyName | string |
Returns
Uint8Array<ArrayBufferLike>
Remarks
These keys can be used for Wallet Id's, Signing Keys, Encryption Keys and for Dapp Samdboxes.
Inherited from
deriveId()
static deriveId(genesisData): Uint8Array<ArrayBufferLike>;Defined in: packages/templates-dev/src/wallet/base-wallet.ts:64
Parameters
| Parameter | Type |
|---|---|
genesisData | WalletGenesisData |
Returns
Uint8Array<ArrayBufferLike>
Inherited from
start()
start(): Promise<void>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:159
Start monitoring this wallet for any transaction activity.
Returns
Promise<void>
Overrides
stop()
stop(): Promise<void>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:178
Stop monitoring this wallet for any transaction activity.
Returns
Promise<void>
Overrides
destroy()
destroy(): Promise<void>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:197
Remove any event listeners from this wallet.
Returns
Promise<void>
Overrides
getTransactions()
getTransactions(): Promise<ExtMap<{
sourceOutputs: Output[];
hash: TransactionHash;
height: number;
transaction: Transaction;
}>>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:201
Fetch all transactions from the blockchain involving this wallet.
Returns
Promise<ExtMap<{ sourceOutputs: Output[]; hash: TransactionHash; height: number; transaction: Transaction; }>>
Remarks
We will want to add a query argument so that workers can use this efficiently:
{
limit?: number;
offset?: number;
sort?: () => number;
filter?: () => boolean;
}This "query" argument should be turned into a generic type as we will want to re-use it for Activities.
Overrides
getUnspents()
getUnspents(): Promise<BlockchainUTXOs>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:264
Fetch all unspents from the blockchain belonging to this wallet.
Returns
Promise<BlockchainUTXOs>
Overrides
getUnspentDirectives()
getUnspentDirectives(): Promise<ExtMap<{
outpointIndex: number;
outpointTransactionHash: Uint8Array<ArrayBufferLike>;
sequenceNumber: number;
unlockingBytecode: {
compiler: Compiler<CompilationContextBch, CompilerConfiguration<CompilationContextBch>, AuthenticationProgramStateCommon>;
data: {
keys: {
privateKeys: {
key: Bytes;
};
};
};
script: string;
};
sourceOutput: {
lockingBytecode: {
compiler: Compiler<CompilationContextBch, CompilerConfiguration<CompilationContextBch>, AuthenticationProgramStateCommon>;
data: {
keys: {
privateKeys: {
key: Bytes;
};
};
};
script: string;
};
token: | {
amount: bigint;
category: Uint8Array;
nft?: {
capability: "none" | "mutable" | "minting";
commitment: Uint8Array;
};
}
| undefined;
valueSatoshis: bigint;
};
}>>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:280
Fetch all unspents from the blockchain belonging to this wallet.
Returns
Promise<ExtMap<{ outpointIndex: number; outpointTransactionHash: Uint8Array<ArrayBufferLike>; sequenceNumber: number; unlockingBytecode: { compiler: Compiler<CompilationContextBch, CompilerConfiguration<CompilationContextBch>, AuthenticationProgramStateCommon>; data: { keys: { privateKeys: { key: Bytes; }; }; }; script: string; }; sourceOutput: { lockingBytecode: { compiler: Compiler<CompilationContextBch, CompilerConfiguration<CompilationContextBch>, AuthenticationProgramStateCommon>; data: { keys: { privateKeys: { key: Bytes; }; }; }; script: string; }; token: | { amount: bigint; category: Uint8Array; nft?: { capability: "none" | "mutable" | "minting"; commitment: Uint8Array; }; } | undefined; valueSatoshis: bigint; }; }>>
Remarks
I was considering removing this and just storing unspents as "UTXOSignable"s. But that might not be ideal if we want to have Watch-only wallets. A better approach might be to have Fetch Unspents return Array<UTXO | UTXOSignable> Still need to flesh that out.
EDIT: We're going to want to store state for caching anyway... May as well just getUnspentDirectives() from the local state instead of fetch. Likewise for balances.
Overrides
BaseWallet.getUnspentDirectives
getBalanceSats()
getBalanceSats(): Promise<bigint>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:318
Get the satoshi balance of this wallet.
Returns
Promise<bigint>
Remarks
Consider confirmed/unconfirmed balances (or some other representation).
This becomes important in some instances because services like BitPay require one confirmation. This'll also have bearing on how we define our UTXO Selection strategies.
Overrides
getBalanceTokens()
getBalanceTokens(): Promise<TokenBalances>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:331
Get the token balance of this wallet.
Returns
Promise<TokenBalances>
Remarks
Consider confirmed/unconfirmed balances (or some other representation).
This becomes important in some instances because services like BitPay require one confirmation. This'll also have bearing on how we define our UTXO Selection strategies.
Overrides
getAddresses()
getAddresses(): Promise<ExtMap<Address>>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:344
Get all addresses belonging to this wallet.
Returns
Promise<ExtMap<Address>>
Overrides
getReceivingAddress()
getReceivingAddress(): Promise<Address>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:350
Get the address that this wallet should receive to.
Returns
Promise<Address>
Overrides
BaseWallet.getReceivingAddress
signTransaction()
signTransaction(txTemplate): Promise<TransactionBuilder>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:354
Select UTXOs from this wallet to meet the amounts required.
Parameters
| Parameter | Type |
|---|---|
txTemplate | Partial<TransactionTemplate> |
Returns
Promise<TransactionBuilder>
Remarks
TODO: We are going to want to return the Transaction that was compiled.
TODO: This should accept a second argument (probably function) that can filter/sory UTXOs. The intent here is to provide a "spending policy". E.g. Only use (or prioritise) UTXOs with 1-conf.
Overrides
sendTransaction()
sendTransaction(txTemplate): Promise<Uint8Array<ArrayBufferLike>>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:386
Select UTXOs from this wallet to meet the amounts required and broadcast it to the Blockchain.
Parameters
| Parameter | Type |
|---|---|
txTemplate | Partial<TransactionTemplate> |
Returns
Promise<Uint8Array<ArrayBufferLike>>
Remarks
TODO: We are going to want to return the Transaction that was compiled.
Overrides
instantiateTemplate()
instantiateTemplate<T>(
template,
instantiationData,
scope): Promise<TemplateInstance<T>>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:400
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends object | object |
Parameters
| Parameter | Type | Default value |
|---|---|---|
template | T | undefined |
instantiationData | CompilationData | undefined |
scope | string | '' |
Returns
Promise<TemplateInstance<T>>
getId()
getId(): Promise<string>;Defined in: packages/templates-dev/src/wallet/base-wallet.ts:77
Get the ID for this wallet.
Returns
Promise<string>
Inherited from
getEncryptionKey()
getEncryptionKey(): Promise<string>;Defined in: packages/templates-dev/src/wallet/base-wallet.ts:86
Get the encryption key to use for this wallet.
Returns
Promise<string>
Inherited from
getSigningKey()
getSigningKey(): Promise<string>;Defined in: packages/templates-dev/src/wallet/base-wallet.ts:95
Get the signing key to use for this wallet.
Returns
Promise<string>
Inherited from
getUnspentTokens()
getUnspentTokens(): Promise<BlockchainUTXOs>;Defined in: packages/templates-dev/src/wallet/base-wallet.ts:144
Fetch all unspents tokens from the blockchain belonging to this wallet.
Returns
Promise<BlockchainUTXOs>
Inherited from
on()
on<K>(
type,
listener,
debounceMilliseconds?): OffCallback;Defined in: packages/core/dist/primitives.d.ts:593
Registers a listener for the specified event type.
Type Parameters
| Type Parameter | Description |
|---|---|
K extends keyof WalletEvents | The event type key |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | K | The event type to listen for |
listener | Listener<WalletEvents[K]> | The function to call when the event is emitted |
debounceMilliseconds? | number | Optional debounce time in milliseconds |
Returns
OffCallback
A callback function that can be used to unregister this listener
Example
const off = emitter.on('data-change', (data) => {
console.log('Data updated:', data);
}, 300); // Debounce for 300ms
// Later, unregister the listener
off();Inherited from
once()
once<K>(
type,
listener,
debounceMilliseconds?): OffCallback;Defined in: packages/core/dist/primitives.d.ts:611
Registers a one-time listener for the specified event type. The listener will be automatically removed after being called once.
Type Parameters
| Type Parameter | Description |
|---|---|
K extends keyof WalletEvents | The event type key |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | K | The event type to listen for |
listener | Listener<WalletEvents[K]> | The function to call when the event is emitted |
debounceMilliseconds? | number | Optional debounce time in milliseconds |
Returns
OffCallback
A callback function that can be used to unregister this listener before it fires
Example
emitter.once('user-login', ({ userId }) => {
console.log(`Welcome ${userId}! This will only show once.`);
});Inherited from
off()
off<K>(type, listener): void;Defined in: packages/core/dist/primitives.d.ts:626
Removes a specific listener for the given event type.
Type Parameters
| Type Parameter | Description |
|---|---|
K extends keyof WalletEvents | The event type key |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | K | The event type to remove the listener from |
listener | Listener<WalletEvents[K]> | The listener function to remove |
Returns
void
Example
const handler = (data) => console.log(data);
emitter.on('test', handler);
emitter.off('test', handler); // Removes the listenerInherited from
emit()
emit<K>(type, payload): boolean;Defined in: packages/core/dist/primitives.d.ts:648
Emits an event of the specified type with the given payload. All registered listeners for this event type will be called.
Type Parameters
| Type Parameter | Description |
|---|---|
K extends keyof WalletEvents | The event type key |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | K | The event type to emit |
payload | WalletEvents[K] | The data to pass to all listeners |
Returns
boolean
true if there were listeners for this event, false otherwise
Example
const hasListeners = emitter.emit('user-login', {
userId: '123',
timestamp: Date.now()
});
if (!hasListeners) {
console.log('No one was listening for user-login events');
}Inherited from
removeAllListeners()
removeAllListeners(): void;Defined in: packages/core/dist/primitives.d.ts:659
Removes all listeners for all events. This effectively resets the EventEmitter to its initial state.
Returns
void
Example
emitter.removeAllListeners();
// All previously registered listeners are now goneInherited from
waitFor()
waitFor<K>(
type,
predicate,
timeoutMs?): Promise<WalletEvents[K]>;Defined in: packages/core/dist/primitives.d.ts:685
Returns a Promise that resolves when an event of the specified type is emitted and matches the given predicate.
Type Parameters
| Type Parameter | Description |
|---|---|
K extends keyof WalletEvents | The event type key |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | K | The event type to wait for |
predicate | (payload) => boolean | A function that determines if the event payload matches what we're waiting for |
timeoutMs? | number | Optional timeout in milliseconds. If specified, the promise will reject after this time |
Returns
Promise<WalletEvents[K]>
A Promise that resolves with the event payload when the condition is met
Throws
If the timeout is reached before a matching event occurs
Example
try {
const loginData = await emitter.waitFor(
'user-login',
({ userId }) => userId === 'admin',
5000 // Wait up to 5 seconds
);
console.log('Admin logged in:', loginData);
} catch (error) {
console.log('Timeout: Admin never logged in');
}Inherited from
Properties
| Property | Modifier | Type | Default value | Overrides | Defined in |
|---|---|---|---|---|---|
blockchain | readonly | WalletBlockchain | undefined | BaseWallet.blockchain | packages/templates-dev/src/wallet/wallet-p2pkh.ts:126 |
genesisData | readonly | WalletP2PKHGenesisData | undefined | BaseWallet.genesisData | packages/templates-dev/src/wallet/wallet-p2pkh.ts:129 |
privateKey | readonly | PrivateKey | undefined | - | packages/templates-dev/src/wallet/wallet-p2pkh.ts:132 |
isStarted | public | boolean | false | - | packages/templates-dev/src/wallet/wallet-p2pkh.ts:135 |
status | public | string | null | null | - | packages/templates-dev/src/wallet/wallet-p2pkh.ts:136 |
useWalletP2PKH()
function useWalletP2PKH<T>(dependencies, genesisData): Promise<T>;Defined in: packages/templates-dev/src/wallet/wallet-p2pkh.ts:485
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends WalletP2PKH | WalletP2PKH |
Parameters
| Parameter | Type |
|---|---|
dependencies | WalletDependencies |
genesisData | WalletP2PKHGenesisData |
Returns
Promise<T>