Skip to content

Commit 9a11482

Browse files
authored
Merge pull request #17 from lightninglabs/add-tapd
Add Taproot Assets support
2 parents 62a5fd2 + 073bed1 commit 9a11482

File tree

20 files changed

+3097
-9
lines changed

20 files changed

+3097
-9
lines changed

lib/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export { default as LndApi } from './lnd';
22
export { default as LoopApi } from './loop';
33
export { default as PoolApi } from './pool';
44
export { default as FaradayApi } from './faraday';
5+
export { default as TaprootAssetsApi } from './tapd';
56
export { default as LitApi } from './lit';

lib/api/tapd.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { serviceNames as sn } from '../types/proto/schema';
2+
import { AssetWallet } from '../types/proto/tapd/assetwalletrpc/assetwallet';
3+
import { Mint } from '../types/proto/tapd/mintrpc/mint';
4+
import { TaprootAssets } from '../types/proto/tapd/taprootassets';
5+
import { Universe } from '../types/proto/tapd/universerpc/universe';
6+
7+
/**
8+
* An API wrapper to communicate with the Taproot Assets node via GRPC
9+
*/
10+
class TaprootAssetsApi {
11+
taprootAssets: TaprootAssets;
12+
assetWallet: AssetWallet;
13+
mint: Mint;
14+
universe: Universe;
15+
16+
constructor(createRpc: Function, lnc: any) {
17+
this.taprootAssets = createRpc(sn.taprpc.TaprootAssets, lnc);
18+
this.mint = createRpc(sn.mintrpc.Mint, lnc);
19+
this.assetWallet = createRpc(sn.assetwalletrpc.AssetWallet, lnc);
20+
this.universe = createRpc(sn.universerpc.Universe, lnc);
21+
}
22+
}
23+
24+
export default TaprootAssetsApi;

lib/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
export * from './types/proto';
22
export { camelKeysToSnake, isObject, snakeKeysToCamel } from './util/objects';
3-
export { LndApi, LoopApi, PoolApi, FaradayApi, LitApi } from './api';
3+
export {
4+
LndApi,
5+
LoopApi,
6+
PoolApi,
7+
FaradayApi,
8+
LitApi,
9+
TaprootAssetsApi
10+
} from './api';
411
export { subscriptionMethods } from './types/proto/schema';

lib/types/proto/assetwalletrpc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './tapd/assetwalletrpc/assetwallet';

lib/types/proto/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import * as watchtowerrpc from './watchtowerrpc';
1111
import * as wtclientrpc from './wtclientrpc';
1212
import * as looprpc from './looprpc';
1313
import * as poolrpc from './poolrpc';
14+
import * as assetwalletrpc from './assetwalletrpc';
15+
import * as mintrpc from './mintrpc';
16+
import * as taprpc from './taprpc';
17+
import * as universerpc from './universerpc';
1418
export {
1519
frdrpc,
1620
litrpc,
@@ -24,5 +28,9 @@ export {
2428
watchtowerrpc,
2529
wtclientrpc,
2630
looprpc,
27-
poolrpc
31+
poolrpc,
32+
assetwalletrpc,
33+
mintrpc,
34+
taprpc,
35+
universerpc
2836
};

lib/types/proto/mintrpc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './tapd/mintrpc/mint';

lib/types/proto/schema.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ export const serviceNames = {
2727
ChannelAuctioneer: 'poolrpc.ChannelAuctioneer',
2828
HashMail: 'poolrpc.HashMail',
2929
Trader: 'poolrpc.Trader'
30-
}
30+
},
31+
assetwalletrpc: { AssetWallet: 'assetwalletrpc.AssetWallet' },
32+
mintrpc: { Mint: 'mintrpc.Mint' },
33+
taprpc: { TaprootAssets: 'taprpc.TaprootAssets' },
34+
universerpc: { Universe: 'universerpc.Universe' }
3135
};
3236

3337
// This array contains the list of methods that are server streaming. It is
@@ -64,5 +68,6 @@ export const subscriptionMethods = [
6468
'looprpc.SwapClient.Monitor',
6569
'poolrpc.ChannelAuctioneer.SubscribeBatchAuction',
6670
'poolrpc.ChannelAuctioneer.SubscribeSidecar',
67-
'poolrpc.HashMail.RecvStream'
71+
'poolrpc.HashMail.RecvStream',
72+
'taprpc.TaprootAssets.SubscribeSendAssetEventNtfns'
6873
];
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
/* eslint-disable */
2+
import type {
3+
KeyDescriptor,
4+
ScriptKey,
5+
SendAssetResponse
6+
} from '../taprootassets';
7+
8+
export interface FundVirtualPsbtRequest {
9+
/**
10+
* Use an existing PSBT packet as the template for the funded PSBT.
11+
*
12+
* TODO(guggero): Actually implement this. We can't use the "reserved"
13+
* keyword here because we're in a oneof, so we add the field but implement
14+
* it later.
15+
*/
16+
psbt: Uint8Array | string | undefined;
17+
/** Use the asset outputs and optional asset inputs from this raw template. */
18+
raw: TxTemplate | undefined;
19+
}
20+
21+
export interface FundVirtualPsbtResponse {
22+
/** The funded but not yet signed PSBT packet. */
23+
fundedPsbt: Uint8Array | string;
24+
/** The index of the added change output or -1 if no change was left over. */
25+
changeOutputIndex: number;
26+
}
27+
28+
export interface TxTemplate {
29+
/**
30+
* An optional list of inputs to use. Every input must be an asset UTXO known
31+
* to the wallet. The sum of all inputs must be greater than or equal to the
32+
* sum of all outputs.
33+
*
34+
* If no inputs are specified, asset coin selection will be performed instead
35+
* and inputs of sufficient value will be added to the resulting PSBT.
36+
*/
37+
inputs: PrevId[];
38+
/**
39+
* A map of all Taproot Asset addresses mapped to the anchor transaction's
40+
* output index that should be sent to.
41+
*/
42+
recipients: { [key: string]: string };
43+
}
44+
45+
export interface TxTemplate_RecipientsEntry {
46+
key: string;
47+
value: string;
48+
}
49+
50+
export interface PrevId {
51+
/** The bitcoin anchor output on chain that contains the input asset. */
52+
outpoint: OutPoint | undefined;
53+
/** The asset ID of the previous asset tree. */
54+
id: Uint8Array | string;
55+
/**
56+
* The tweaked Taproot output key committing to the possible spending
57+
* conditions of the asset.
58+
*/
59+
scriptKey: Uint8Array | string;
60+
}
61+
62+
export interface OutPoint {
63+
/** Raw bytes representing the transaction id. */
64+
txid: Uint8Array | string;
65+
/** The index of the output on the transaction. */
66+
outputIndex: number;
67+
}
68+
69+
export interface SignVirtualPsbtRequest {
70+
/**
71+
* The PSBT of the virtual transaction that should be signed. The PSBT must
72+
* contain all required inputs, outputs, UTXO data and custom fields required
73+
* to identify the signing key.
74+
*/
75+
fundedPsbt: Uint8Array | string;
76+
}
77+
78+
export interface SignVirtualPsbtResponse {
79+
/** The signed virtual transaction in PSBT format. */
80+
signedPsbt: Uint8Array | string;
81+
/** The indices of signed inputs. */
82+
signedInputs: number[];
83+
}
84+
85+
export interface AnchorVirtualPsbtsRequest {
86+
/**
87+
* The list of virtual transactions that should be merged and committed to in
88+
* the BTC level anchor transaction.
89+
*/
90+
virtualPsbts: Uint8Array | string[];
91+
}
92+
93+
export interface NextInternalKeyRequest {
94+
keyFamily: number;
95+
}
96+
97+
export interface NextInternalKeyResponse {
98+
internalKey: KeyDescriptor | undefined;
99+
}
100+
101+
export interface NextScriptKeyRequest {
102+
keyFamily: number;
103+
}
104+
105+
export interface NextScriptKeyResponse {
106+
scriptKey: ScriptKey | undefined;
107+
}
108+
109+
export interface ProveAssetOwnershipRequest {
110+
assetId: Uint8Array | string;
111+
scriptKey: Uint8Array | string;
112+
}
113+
114+
export interface ProveAssetOwnershipResponse {
115+
proofWithWitness: Uint8Array | string;
116+
}
117+
118+
export interface VerifyAssetOwnershipRequest {
119+
proofWithWitness: Uint8Array | string;
120+
}
121+
122+
export interface VerifyAssetOwnershipResponse {
123+
validProof: boolean;
124+
}
125+
126+
export interface AssetWallet {
127+
/**
128+
* FundVirtualPsbt selects inputs from the available asset commitments to fund
129+
* a virtual transaction matching the template.
130+
*/
131+
fundVirtualPsbt(
132+
request?: DeepPartial<FundVirtualPsbtRequest>
133+
): Promise<FundVirtualPsbtResponse>;
134+
/**
135+
* SignVirtualPsbt signs the inputs of a virtual transaction and prepares the
136+
* commitments of the inputs and outputs.
137+
*/
138+
signVirtualPsbt(
139+
request?: DeepPartial<SignVirtualPsbtRequest>
140+
): Promise<SignVirtualPsbtResponse>;
141+
/**
142+
* AnchorVirtualPsbts merges and then commits multiple virtual transactions in
143+
* a single BTC level anchor transaction.
144+
*
145+
* TODO(guggero): Actually implement accepting and merging multiple
146+
* transactions.
147+
*/
148+
anchorVirtualPsbts(
149+
request?: DeepPartial<AnchorVirtualPsbtsRequest>
150+
): Promise<SendAssetResponse>;
151+
/**
152+
* NextInternalKey derives the next internal key for the given key family and
153+
* stores it as an internal key in the database to make sure it is identified
154+
* as a local key later on when importing proofs. While an internal key can
155+
* also be used as the internal key of a script key, it is recommended to use
156+
* the NextScriptKey RPC instead, to make sure the tweaked Taproot output key
157+
* is also recognized as a local key.
158+
*/
159+
nextInternalKey(
160+
request?: DeepPartial<NextInternalKeyRequest>
161+
): Promise<NextInternalKeyResponse>;
162+
/**
163+
* NextScriptKey derives the next script key (and its corresponding internal
164+
* key) and stores them both in the database to make sure they are identified
165+
* as local keys later on when importing proofs.
166+
*/
167+
nextScriptKey(
168+
request?: DeepPartial<NextScriptKeyRequest>
169+
): Promise<NextScriptKeyResponse>;
170+
/**
171+
* ProveAssetOwnership creates an ownership proof embedded in an asset
172+
* transition proof. That ownership proof is a signed virtual transaction
173+
* spending the asset with a valid witness to prove the prover owns the keys
174+
* that can spend the asset.
175+
*/
176+
proveAssetOwnership(
177+
request?: DeepPartial<ProveAssetOwnershipRequest>
178+
): Promise<ProveAssetOwnershipResponse>;
179+
/**
180+
* VerifyAssetOwnership verifies the asset ownership proof embedded in the
181+
* given transition proof of an asset and returns true if the proof is valid.
182+
*/
183+
verifyAssetOwnership(
184+
request?: DeepPartial<VerifyAssetOwnershipRequest>
185+
): Promise<VerifyAssetOwnershipResponse>;
186+
}
187+
188+
type Builtin =
189+
| Date
190+
| Function
191+
| Uint8Array
192+
| string
193+
| number
194+
| boolean
195+
| undefined;
196+
197+
type DeepPartial<T> = T extends Builtin
198+
? T
199+
: T extends Array<infer U>
200+
? Array<DeepPartial<U>>
201+
: T extends ReadonlyArray<infer U>
202+
? ReadonlyArray<DeepPartial<U>>
203+
: T extends {}
204+
? { [K in keyof T]?: DeepPartial<T[K]> }
205+
: Partial<T>;

0 commit comments

Comments
 (0)