diff --git a/modules/sdk-core/src/bitgo/index.ts b/modules/sdk-core/src/bitgo/index.ts index fa58c3b22a..af8be04dea 100644 --- a/modules/sdk-core/src/bitgo/index.ts +++ b/modules/sdk-core/src/bitgo/index.ts @@ -17,6 +17,7 @@ export * from './keychain'; export * as bitcoin from './legacyBitcoin'; export * from './market'; export * from './pendingApproval'; +export { WalletProofs } from './proofs'; export * from './recovery'; export * from './staking'; export * from './trading'; diff --git a/modules/sdk-core/src/bitgo/proofs/WalletProofs.ts b/modules/sdk-core/src/bitgo/proofs/WalletProofs.ts new file mode 100644 index 0000000000..e013d3f5ff --- /dev/null +++ b/modules/sdk-core/src/bitgo/proofs/WalletProofs.ts @@ -0,0 +1,41 @@ +import { IWallet } from '../wallet'; +import { RequestTracer } from '../utils'; +import { AccountSnapshot, UserVerificationElements } from './types'; + +export class WalletProofs { + public wallet: IWallet; + + constructor(wallet: IWallet) { + this.wallet = wallet; + } + + /** + * Get the liability proofs for a Go Account - these can be used to verify the balances of the account + * were included in the total Go Account liabilities published by BitGo on the public proof of solvency page. + * @returns UserVerificationElements + */ + async getLiabilityProofs(): Promise { + const reqId = new RequestTracer(); + this.wallet.bitgo.setRequestTracer(reqId); + + return (await this.wallet.bitgo + .get(this.wallet.bitgo.url('/proofs-service/wallet/' + this.wallet.id() + '/liability-proofs')) + .send() + .result()) as UserVerificationElements; + } + + /** + * Get the account snapshot for a Go Account - this provides a snapshot of the account's balances at the + * latest proof generation date (for proof of solvency). + * @returns AccountSnapshot + */ + async getAccountSnapshot(): Promise { + const reqId = new RequestTracer(); + this.wallet.bitgo.setRequestTracer(reqId); + + return (await this.wallet.bitgo + .get(this.wallet.bitgo.url('/proofs-service/wallet/' + this.wallet.id() + '/account-snapshot')) + .send() + .result()) as AccountSnapshot; + } +} diff --git a/modules/sdk-core/src/bitgo/proofs/index.ts b/modules/sdk-core/src/bitgo/proofs/index.ts new file mode 100644 index 0000000000..3e2fee0990 --- /dev/null +++ b/modules/sdk-core/src/bitgo/proofs/index.ts @@ -0,0 +1 @@ +export { WalletProofs } from './WalletProofs'; diff --git a/modules/sdk-core/src/bitgo/proofs/types.ts b/modules/sdk-core/src/bitgo/proofs/types.ts new file mode 100644 index 0000000000..5b213aff38 --- /dev/null +++ b/modules/sdk-core/src/bitgo/proofs/types.ts @@ -0,0 +1,61 @@ +import * as t from 'io-ts'; + +// type definitions for user verification elements (returned by liability proofs route) +export const BalancesCodec = t.type({ + Asset: t.string, + Amount: t.string, +}); + +export type Balance = t.TypeOf; + +export const LowerProof = t.type({ + Proof: t.string, + VerificationKey: t.string, + MerkleRoot: t.string, + MerkleRootWithAssetSumHash: t.string, + MerklePath: t.array(t.string), + MerklePosition: t.number, +}); + +export type LowerProof = t.TypeOf; + +export const TopProof = t.type({ + Proof: t.string, + VerificationKey: t.string, + MerkleRoot: t.string, + MerkleRootWithAssetSumHash: t.string, + AssetSum: t.array(BalancesCodec), +}); + +export type TopProof = t.TypeOf; + +export const UserVerificationElements = t.type({ + AccountInfo: t.type({ + WalletId: t.string, + Balance: t.array(BalancesCodec), + }), + ProofInfo: t.type({ + UserMerklePath: t.array(t.string), + UserMerklePosition: t.number, + BottomProof: LowerProof, + MiddleProof: LowerProof, + TopProof: TopProof, + }), +}); + +export type UserVerificationElements = t.TypeOf; + +// type definitions for account snapshots +export const SnapshotBalance = t.type({ + asset: t.string, + amount: t.string, +}); + +export type SnapshotBalance = t.TypeOf; + +export const AccountSnapshot = t.type({ + snapshotDate: t.string, + balances: t.array(SnapshotBalance), +}); + +export type AccountSnapshot = t.TypeOf;