Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export { default as LndApi } from './lnd';
export { default as LoopApi } from './loop';
export { default as PoolApi } from './pool';
export { default as FaradayApi } from './faraday';
export { default as TaprootAssetsApi } from './tapd';
export { default as LitApi } from './lit';
24 changes: 24 additions & 0 deletions lib/api/tapd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { serviceNames as sn } from '../types/proto/schema';
import { AssetWallet } from '../types/proto/tapd/assetwalletrpc/assetwallet';
import { Mint } from '../types/proto/tapd/mintrpc/mint';
import { TaprootAssets } from '../types/proto/tapd/taprootassets';
import { Universe } from '../types/proto/tapd/universerpc/universe';

/**
* An API wrapper to communicate with the Taproot Assets node via GRPC
*/
class TaprootAssetsApi {
taprootAssets: TaprootAssets;
assetWallet: AssetWallet;
mint: Mint;
universe: Universe;

constructor(createRpc: Function, lnc: any) {
this.taprootAssets = createRpc(sn.taprpc.TaprootAssets, lnc);
this.mint = createRpc(sn.mintrpc.Mint, lnc);
this.assetWallet = createRpc(sn.assetwalletrpc.AssetWallet, lnc);
this.universe = createRpc(sn.universerpc.Universe, lnc);
}
}

export default TaprootAssetsApi;
9 changes: 8 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
export * from './types/proto';
export { camelKeysToSnake, isObject, snakeKeysToCamel } from './util/objects';
export { LndApi, LoopApi, PoolApi, FaradayApi, LitApi } from './api';
export {
LndApi,
LoopApi,
PoolApi,
FaradayApi,
LitApi,
TaprootAssetsApi
} from './api';
export { subscriptionMethods } from './types/proto/schema';
1 change: 1 addition & 0 deletions lib/types/proto/assetwalletrpc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './tapd/assetwalletrpc/assetwallet';
10 changes: 9 additions & 1 deletion lib/types/proto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import * as watchtowerrpc from './watchtowerrpc';
import * as wtclientrpc from './wtclientrpc';
import * as looprpc from './looprpc';
import * as poolrpc from './poolrpc';
import * as assetwalletrpc from './assetwalletrpc';
import * as mintrpc from './mintrpc';
import * as taprpc from './taprpc';
import * as universerpc from './universerpc';
export {
frdrpc,
litrpc,
Expand All @@ -24,5 +28,9 @@ export {
watchtowerrpc,
wtclientrpc,
looprpc,
poolrpc
poolrpc,
assetwalletrpc,
mintrpc,
taprpc,
universerpc
};
1 change: 1 addition & 0 deletions lib/types/proto/mintrpc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './tapd/mintrpc/mint';
9 changes: 7 additions & 2 deletions lib/types/proto/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export const serviceNames = {
ChannelAuctioneer: 'poolrpc.ChannelAuctioneer',
HashMail: 'poolrpc.HashMail',
Trader: 'poolrpc.Trader'
}
},
assetwalletrpc: { AssetWallet: 'assetwalletrpc.AssetWallet' },
mintrpc: { Mint: 'mintrpc.Mint' },
taprpc: { TaprootAssets: 'taprpc.TaprootAssets' },
universerpc: { Universe: 'universerpc.Universe' }
};

// This array contains the list of methods that are server streaming. It is
Expand Down Expand Up @@ -64,5 +68,6 @@ export const subscriptionMethods = [
'looprpc.SwapClient.Monitor',
'poolrpc.ChannelAuctioneer.SubscribeBatchAuction',
'poolrpc.ChannelAuctioneer.SubscribeSidecar',
'poolrpc.HashMail.RecvStream'
'poolrpc.HashMail.RecvStream',
'taprpc.TaprootAssets.SubscribeSendAssetEventNtfns'
];
205 changes: 205 additions & 0 deletions lib/types/proto/tapd/assetwalletrpc/assetwallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
/* eslint-disable */
import type {
KeyDescriptor,
ScriptKey,
SendAssetResponse
} from '../taprootassets';

export interface FundVirtualPsbtRequest {
/**
* Use an existing PSBT packet as the template for the funded PSBT.
*
* TODO(guggero): Actually implement this. We can't use the "reserved"
* keyword here because we're in a oneof, so we add the field but implement
* it later.
*/
psbt: Uint8Array | string | undefined;
/** Use the asset outputs and optional asset inputs from this raw template. */
raw: TxTemplate | undefined;
}

export interface FundVirtualPsbtResponse {
/** The funded but not yet signed PSBT packet. */
fundedPsbt: Uint8Array | string;
/** The index of the added change output or -1 if no change was left over. */
changeOutputIndex: number;
}

export interface TxTemplate {
/**
* An optional list of inputs to use. Every input must be an asset UTXO known
* to the wallet. The sum of all inputs must be greater than or equal to the
* sum of all outputs.
*
* If no inputs are specified, asset coin selection will be performed instead
* and inputs of sufficient value will be added to the resulting PSBT.
*/
inputs: PrevId[];
/**
* A map of all Taproot Asset addresses mapped to the anchor transaction's
* output index that should be sent to.
*/
recipients: { [key: string]: string };
}

export interface TxTemplate_RecipientsEntry {
key: string;
value: string;
}

export interface PrevId {
/** The bitcoin anchor output on chain that contains the input asset. */
outpoint: OutPoint | undefined;
/** The asset ID of the previous asset tree. */
id: Uint8Array | string;
/**
* The tweaked Taproot output key committing to the possible spending
* conditions of the asset.
*/
scriptKey: Uint8Array | string;
}

export interface OutPoint {
/** Raw bytes representing the transaction id. */
txid: Uint8Array | string;
/** The index of the output on the transaction. */
outputIndex: number;
}

export interface SignVirtualPsbtRequest {
/**
* The PSBT of the virtual transaction that should be signed. The PSBT must
* contain all required inputs, outputs, UTXO data and custom fields required
* to identify the signing key.
*/
fundedPsbt: Uint8Array | string;
}

export interface SignVirtualPsbtResponse {
/** The signed virtual transaction in PSBT format. */
signedPsbt: Uint8Array | string;
/** The indices of signed inputs. */
signedInputs: number[];
}

export interface AnchorVirtualPsbtsRequest {
/**
* The list of virtual transactions that should be merged and committed to in
* the BTC level anchor transaction.
*/
virtualPsbts: Uint8Array | string[];
}

export interface NextInternalKeyRequest {
keyFamily: number;
}

export interface NextInternalKeyResponse {
internalKey: KeyDescriptor | undefined;
}

export interface NextScriptKeyRequest {
keyFamily: number;
}

export interface NextScriptKeyResponse {
scriptKey: ScriptKey | undefined;
}

export interface ProveAssetOwnershipRequest {
assetId: Uint8Array | string;
scriptKey: Uint8Array | string;
}

export interface ProveAssetOwnershipResponse {
proofWithWitness: Uint8Array | string;
}

export interface VerifyAssetOwnershipRequest {
proofWithWitness: Uint8Array | string;
}

export interface VerifyAssetOwnershipResponse {
validProof: boolean;
}

export interface AssetWallet {
/**
* FundVirtualPsbt selects inputs from the available asset commitments to fund
* a virtual transaction matching the template.
*/
fundVirtualPsbt(
request?: DeepPartial<FundVirtualPsbtRequest>
): Promise<FundVirtualPsbtResponse>;
/**
* SignVirtualPsbt signs the inputs of a virtual transaction and prepares the
* commitments of the inputs and outputs.
*/
signVirtualPsbt(
request?: DeepPartial<SignVirtualPsbtRequest>
): Promise<SignVirtualPsbtResponse>;
/**
* AnchorVirtualPsbts merges and then commits multiple virtual transactions in
* a single BTC level anchor transaction.
*
* TODO(guggero): Actually implement accepting and merging multiple
* transactions.
*/
anchorVirtualPsbts(
request?: DeepPartial<AnchorVirtualPsbtsRequest>
): Promise<SendAssetResponse>;
/**
* NextInternalKey derives the next internal key for the given key family and
* stores it as an internal key in the database to make sure it is identified
* as a local key later on when importing proofs. While an internal key can
* also be used as the internal key of a script key, it is recommended to use
* the NextScriptKey RPC instead, to make sure the tweaked Taproot output key
* is also recognized as a local key.
*/
nextInternalKey(
request?: DeepPartial<NextInternalKeyRequest>
): Promise<NextInternalKeyResponse>;
/**
* NextScriptKey derives the next script key (and its corresponding internal
* key) and stores them both in the database to make sure they are identified
* as local keys later on when importing proofs.
*/
nextScriptKey(
request?: DeepPartial<NextScriptKeyRequest>
): Promise<NextScriptKeyResponse>;
/**
* ProveAssetOwnership creates an ownership proof embedded in an asset
* transition proof. That ownership proof is a signed virtual transaction
* spending the asset with a valid witness to prove the prover owns the keys
* that can spend the asset.
*/
proveAssetOwnership(
request?: DeepPartial<ProveAssetOwnershipRequest>
): Promise<ProveAssetOwnershipResponse>;
/**
* VerifyAssetOwnership verifies the asset ownership proof embedded in the
* given transition proof of an asset and returns true if the proof is valid.
*/
verifyAssetOwnership(
request?: DeepPartial<VerifyAssetOwnershipRequest>
): Promise<VerifyAssetOwnershipResponse>;
}

type Builtin =
| Date
| Function
| Uint8Array
| string
| number
| boolean
| undefined;

type DeepPartial<T> = T extends Builtin
? T
: T extends Array<infer U>
? Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U>
? ReadonlyArray<DeepPartial<U>>
: T extends {}
? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;
Loading