Skip to content

Commit 3e354e1

Browse files
authored
Merge pull request #6533 from BitGo/btc-0-temp-test
feat: add proofs-service API class
2 parents 4f95b75 + 671b75b commit 3e354e1

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

modules/sdk-core/src/bitgo/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export * from './keychain';
1717
export * as bitcoin from './legacyBitcoin';
1818
export * from './market';
1919
export * from './pendingApproval';
20+
export { WalletProofs } from './proofs';
2021
export * from './recovery';
2122
export * from './staking';
2223
export * from './trading';
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { IWallet } from '../wallet';
2+
import { RequestTracer } from '../utils';
3+
import { AccountSnapshot, UserVerificationElements } from './types';
4+
5+
export class WalletProofs {
6+
public wallet: IWallet;
7+
8+
constructor(wallet: IWallet) {
9+
this.wallet = wallet;
10+
}
11+
12+
/**
13+
* Get the liability proofs for a Go Account - these can be used to verify the balances of the account
14+
* were included in the total Go Account liabilities published by BitGo on the public proof of solvency page.
15+
* @returns UserVerificationElements
16+
*/
17+
async getLiabilityProofs(): Promise<UserVerificationElements> {
18+
const reqId = new RequestTracer();
19+
this.wallet.bitgo.setRequestTracer(reqId);
20+
21+
return (await this.wallet.bitgo
22+
.get(this.wallet.bitgo.url('/proofs-service/wallet/' + this.wallet.id() + '/liability-proofs'))
23+
.send()
24+
.result()) as UserVerificationElements;
25+
}
26+
27+
/**
28+
* Get the account snapshot for a Go Account - this provides a snapshot of the account's balances at the
29+
* latest proof generation date (for proof of solvency).
30+
* @returns AccountSnapshot
31+
*/
32+
async getAccountSnapshot(): Promise<AccountSnapshot> {
33+
const reqId = new RequestTracer();
34+
this.wallet.bitgo.setRequestTracer(reqId);
35+
36+
return (await this.wallet.bitgo
37+
.get(this.wallet.bitgo.url('/proofs-service/wallet/' + this.wallet.id() + '/account-snapshot'))
38+
.send()
39+
.result()) as AccountSnapshot;
40+
}
41+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { WalletProofs } from './WalletProofs';
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import * as t from 'io-ts';
2+
3+
// type definitions for user verification elements (returned by liability proofs route)
4+
export const BalancesCodec = t.type({
5+
Asset: t.string,
6+
Amount: t.string,
7+
});
8+
9+
export type Balance = t.TypeOf<typeof BalancesCodec>;
10+
11+
export const LowerProof = t.type({
12+
Proof: t.string,
13+
VerificationKey: t.string,
14+
MerkleRoot: t.string,
15+
MerkleRootWithAssetSumHash: t.string,
16+
MerklePath: t.array(t.string),
17+
MerklePosition: t.number,
18+
});
19+
20+
export type LowerProof = t.TypeOf<typeof LowerProof>;
21+
22+
export const TopProof = t.type({
23+
Proof: t.string,
24+
VerificationKey: t.string,
25+
MerkleRoot: t.string,
26+
MerkleRootWithAssetSumHash: t.string,
27+
AssetSum: t.array(BalancesCodec),
28+
});
29+
30+
export type TopProof = t.TypeOf<typeof TopProof>;
31+
32+
export const UserVerificationElements = t.type({
33+
AccountInfo: t.type({
34+
WalletId: t.string,
35+
Balance: t.array(BalancesCodec),
36+
}),
37+
ProofInfo: t.type({
38+
UserMerklePath: t.array(t.string),
39+
UserMerklePosition: t.number,
40+
BottomProof: LowerProof,
41+
MiddleProof: LowerProof,
42+
TopProof: TopProof,
43+
}),
44+
});
45+
46+
export type UserVerificationElements = t.TypeOf<typeof UserVerificationElements>;
47+
48+
// type definitions for account snapshots
49+
export const SnapshotBalance = t.type({
50+
asset: t.string,
51+
amount: t.string,
52+
});
53+
54+
export type SnapshotBalance = t.TypeOf<typeof SnapshotBalance>;
55+
56+
export const AccountSnapshot = t.type({
57+
snapshotDate: t.string,
58+
balances: t.array(SnapshotBalance),
59+
});
60+
61+
export type AccountSnapshot = t.TypeOf<typeof AccountSnapshot>;

0 commit comments

Comments
 (0)