Skip to content

feat: add proofs-service API class #6533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2025
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 modules/sdk-core/src/bitgo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
41 changes: 41 additions & 0 deletions modules/sdk-core/src/bitgo/proofs/WalletProofs.ts
Original file line number Diff line number Diff line change
@@ -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<UserVerificationElements> {
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<AccountSnapshot> {
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;
}
}
1 change: 1 addition & 0 deletions modules/sdk-core/src/bitgo/proofs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { WalletProofs } from './WalletProofs';
61 changes: 61 additions & 0 deletions modules/sdk-core/src/bitgo/proofs/types.ts
Original file line number Diff line number Diff line change
@@ -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<typeof BalancesCodec>;

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<typeof LowerProof>;

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<typeof TopProof>;

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<typeof UserVerificationElements>;

// type definitions for account snapshots
export const SnapshotBalance = t.type({
asset: t.string,
amount: t.string,
});

export type SnapshotBalance = t.TypeOf<typeof SnapshotBalance>;

export const AccountSnapshot = t.type({
snapshotDate: t.string,
balances: t.array(SnapshotBalance),
});

export type AccountSnapshot = t.TypeOf<typeof AccountSnapshot>;
Loading