-
Notifications
You must be signed in to change notification settings - Fork 305
feat: add sdk-core vault module interfaces and scaffolding #9223
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
Open
davidkaplanbitgo
wants to merge
1
commit into
master
Choose a base branch
from
WCN-1192.vault-interfaces
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /** | ||
| * @prettier | ||
| * | ||
| * @experimental The safe client surface is experimental and may change (including breaking | ||
| * changes) before the public release. | ||
| */ | ||
| // Wire/data shapes are owned by @bitgo/public-types — import them where needed rather than | ||
| // re-exporting from sdk-core. | ||
| import type { | ||
| FreezeSafeBody, | ||
| SafeData, | ||
| SafePermission, | ||
| SafeRootKeys, | ||
| SafeShareData, | ||
| SafeShareKeychain, | ||
| SafeShareState, | ||
| } from '@bitgo/public-types'; | ||
| import type { Wallet, WalletShare } from '../wallet'; | ||
|
|
||
| export interface InitializeSafeOptions { | ||
| label: string; | ||
| } | ||
|
|
||
| // Phase 3 — the client hands back the 12 key ids it created in Phase 2: | ||
| export interface FinalizeSafeOptions { | ||
| rootKeys: SafeRootKeys; | ||
| } | ||
|
|
||
| /** | ||
| * Sharing ONE safe wallet with a non-member rides the existing wallet-share handshake (FR-13), | ||
| * so the result is the existing WalletShare shape. | ||
| */ | ||
| export type WalletShareData = WalletShare; | ||
|
|
||
| // ---- per-safe operation options (bodies land in WCN-1203 / WCN-1204) ---- | ||
|
|
||
| export interface CreateSafeWalletOptions { | ||
| coin: string; | ||
| label: string; | ||
| type?: string; | ||
| multisigTypeVersion?: string; | ||
| } | ||
|
|
||
| interface AddSafeMemberBase { | ||
| permissions: SafePermission[]; | ||
| /** required when 'spend' is included — the 4 root user keys ECDH-re-encrypted to the invitee */ | ||
| keychains?: SafeShareKeychain[]; | ||
| message?: string; | ||
| /** when true, suppress the invitation email that would otherwise be sent to `email` */ | ||
| disableEmail?: boolean; | ||
| } | ||
|
|
||
| /** Add a member by either `userId` or `email` — exactly one is required. */ | ||
| export type AddSafeMemberOptions = | ||
| | (AddSafeMemberBase & { userId: string; email?: never }) | ||
| | (AddSafeMemberBase & { email: string; userId?: never }); | ||
|
|
||
| export interface AddSafeWalletMemberOptions { | ||
| walletId: string; | ||
| /** required — sharing re-encrypts the user key, which needs hardened derivation from the passphrase */ | ||
| walletPassphrase: string; | ||
| email?: string; | ||
| permissions?: string[]; | ||
| message?: string; | ||
| } | ||
|
|
||
| export type AcceptSafeShareAsSpenderOptions = { | ||
| safeShareId: string; | ||
| userPassword: string; | ||
| newWalletPassphrase?: string; | ||
| }; | ||
| export type AcceptSafeShareAsNonSpenderOptions = { | ||
| safeShareId: string; | ||
| }; | ||
| export type AcceptSafeShareOptions = AcceptSafeShareAsSpenderOptions | AcceptSafeShareAsNonSpenderOptions; | ||
|
|
||
| /** | ||
| * @experimental | ||
| */ | ||
| export interface ISafe { | ||
| id(): string; | ||
| enterpriseId(): string; | ||
| label(): string; | ||
| status(): SafeData['status']; | ||
| url(extra?: string): string; | ||
| createWallet(params: CreateSafeWalletOptions): Promise<Wallet>; | ||
| // whole-safe: view/admin/spend/dapp; spend opens a key share (also how a spender services a | ||
| // safeShareRequests entry in UMS orgs) | ||
| addMember(params: AddSafeMemberOptions): Promise<SafeData>; | ||
| // share ONE safe wallet, not the whole safe | ||
| addMemberToWallet(params: AddSafeWalletMemberOptions): Promise<WalletShareData>; | ||
| listShares(params?: { state?: SafeShareState }): Promise<SafeShareData[]>; | ||
| acceptShare(params: AcceptSafeShareOptions): Promise<SafeShareData>; | ||
| freeze(params?: FreezeSafeBody): Promise<SafeData>; | ||
| archive(): Promise<SafeData>; | ||
| toJSON(): SafeData; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /** | ||
| * @prettier | ||
| * | ||
| * @experimental The safe client surface is experimental and may change (including breaking | ||
| * changes) before the public release. | ||
| */ | ||
| import { FinalizeSafeOptions, InitializeSafeOptions } from './iSafe'; | ||
| import { Safe } from './safe'; | ||
|
|
||
| /** | ||
| * Options for safe creation. | ||
| * | ||
| * v1 targets the HOT custody model only: the multisig root user/backup keys are generated locally | ||
| * by the SDK, encrypted with `passphrase`, and registered on BitGo; the MPC roots run the standard | ||
| * hot ceremonies with the same passphrase. Self-managed cold keys and custodial safes are out of | ||
| * scope for v1. | ||
| */ | ||
| export interface CreateSafeOptions { | ||
| label: string; | ||
| passphrase: string; // encrypts the locally-generated multisig user/backup prvs; shared with the MPC ceremonies | ||
| } | ||
|
|
||
| /** Handle returned by `initializeSafe`, threaded into the key ceremonies and finalize. */ | ||
| export interface SafeCreationHandle { | ||
| safeId: string; | ||
| } | ||
|
|
||
| /** | ||
| * The 12 minted root key ids produced by `createSafeKeys`, as 4 ordered [user, backup, bitgo] | ||
| * triplets — exactly the payload `finalizeSafe` consumes. | ||
| */ | ||
| export type SafeKeys = FinalizeSafeOptions; | ||
|
|
||
| export interface ListSafesOptions { | ||
| cursor?: string; // opaque cursor from a previous response's nextCursor | ||
| limit?: number; | ||
| } | ||
|
|
||
| export interface GetSafeOptions { | ||
| id: string; | ||
| } | ||
|
|
||
| /** | ||
| * @experimental | ||
| */ | ||
| export interface ISafes { | ||
| /** | ||
| * One-call convenience wrapper: initialize → createSafeKeys (4 safeId-tagged ceremonies) → | ||
| * finalize → keycard. HOT custody only in v1. | ||
| */ | ||
| generateSafe(params: CreateSafeOptions): Promise<Safe>; | ||
| /** Phase 1 — initialize a safe (metadata only, no key material). */ | ||
| initializeSafe(params: InitializeSafeOptions): Promise<Safe>; | ||
| /** Phase 2 — run the 4 root key ceremonies tagged with `safeId`; returns the 12 minted key ids. */ | ||
| createSafeKeys(params: CreateSafeOptions & SafeCreationHandle): Promise<SafeKeys>; | ||
| /** Phase 3 — finalize a safe with the 12 root key ids. Idempotent. */ | ||
| finalizeSafe(safeId: string, params: FinalizeSafeOptions): Promise<Safe>; | ||
| list(params?: ListSafesOptions): Promise<{ safes: Safe[]; nextCursor?: string }>; | ||
| get(params: GetSafeOptions): Promise<Safe>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export * from './iSafe'; | ||
| export * from './iSafes'; | ||
| export * from './safe'; | ||
| export * from './safes'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| /** | ||
| * @prettier | ||
| * | ||
| * @experimental The safe client surface is experimental and may change (including breaking | ||
| * changes) before the public release. | ||
| */ | ||
| import * as _ from 'lodash'; | ||
| import { FreezeSafeBody, SafeData, SafeShareData, SafeShareState } from '@bitgo/public-types'; | ||
| import { BitGoBase } from '../bitgoBase'; | ||
| import { decodeWithCodec } from '../utils/codecs'; | ||
| import { postWithCodec } from '../utils/postWithCodec'; | ||
| import { Wallet } from '../wallet'; | ||
| import { | ||
| AcceptSafeShareOptions, | ||
| AddSafeMemberOptions, | ||
| AddSafeWalletMemberOptions, | ||
| CreateSafeWalletOptions, | ||
| ISafe, | ||
| WalletShareData, | ||
| } from './iSafe'; | ||
|
|
||
| /** | ||
| * @experimental | ||
| */ | ||
| export class Safe implements ISafe { | ||
| private readonly bitgo: BitGoBase; | ||
| public readonly _safe: SafeData; | ||
|
|
||
| constructor(bitgo: BitGoBase, safeData: SafeData) { | ||
| this.bitgo = bitgo; | ||
| if (!_.isObject(safeData)) { | ||
| throw new Error('safeData has to be an object'); | ||
| } | ||
| if (!_.isString(safeData.id)) { | ||
| throw new Error('safe id has to be a string'); | ||
| } | ||
| if (!_.isString(safeData.enterpriseId)) { | ||
| throw new Error('safe enterpriseId has to be a string'); | ||
| } | ||
| this._safe = safeData; | ||
| } | ||
|
|
||
| id(): string { | ||
| return this._safe.id; | ||
| } | ||
|
|
||
| enterpriseId(): string { | ||
| return this._safe.enterpriseId; | ||
| } | ||
|
|
||
| label(): string { | ||
| return this._safe.label; | ||
| } | ||
|
|
||
| status(): SafeData['status'] { | ||
| return this._safe.status; | ||
| } | ||
|
|
||
| /** | ||
| * Enterprise-scoped v2 URL for this safe, e.g. /api/v2/enterprise/:eId/safes/:safeId | ||
| * @param extra | ||
| */ | ||
| url(extra = ''): string { | ||
| return this.bitgo.url(`/enterprise/${this.enterpriseId()}/safes/${this.id()}${extra}`, 2); | ||
| } | ||
|
|
||
| /** | ||
| * Mint a child wallet in this safe (server-side public derivation — no ceremony). | ||
| * Body lands in WCN-1203. | ||
| */ | ||
| async createWallet(params: CreateSafeWalletOptions): Promise<Wallet> { | ||
| throw new Error('Safe.createWallet is not yet implemented (WCN-1203)'); | ||
| } | ||
|
|
||
| /** | ||
| * Add a member to the whole safe (view/admin/spend). Spend opens a key share. | ||
| * Body lands in WCN-1204. | ||
| */ | ||
| async addMember(params: AddSafeMemberOptions): Promise<SafeData> { | ||
| throw new Error('Safe.addMember is not yet implemented (WCN-1204)'); | ||
| } | ||
|
|
||
| /** | ||
| * Share ONE safe wallet with a non-member via the existing wallet-share handshake (FR-13). | ||
| * Body lands in WCN-1204. | ||
| */ | ||
| async addMemberToWallet(params: AddSafeWalletMemberOptions): Promise<WalletShareData> { | ||
| throw new Error('Safe.addMemberToWallet is not yet implemented (WCN-1204)'); | ||
| } | ||
|
|
||
| /** | ||
| * List the safe key shares visible to the caller. | ||
| * Body lands in WCN-1204. | ||
| */ | ||
| async listShares(params: { state?: SafeShareState } = {}): Promise<SafeShareData[]> { | ||
| throw new Error('Safe.listShares is not yet implemented (WCN-1204)'); | ||
| } | ||
|
|
||
| /** | ||
| * Accept a safe key share addressed to the caller. | ||
| * Body lands in WCN-1204. | ||
| */ | ||
| async acceptShare(params: AcceptSafeShareOptions): Promise<SafeShareData> { | ||
| throw new Error('Safe.acceptShare is not yet implemented (WCN-1204)'); | ||
| } | ||
|
|
||
| /** | ||
| * Freeze the safe — blocks withdrawals on all safe wallets. Safe stays 'active'. | ||
| * @param params | ||
| */ | ||
| async freeze(params: FreezeSafeBody = {}): Promise<SafeData> { | ||
| const response = await postWithCodec(this.bitgo, this.url('/freeze'), FreezeSafeBody, params).result(); | ||
| return decodeWithCodec(SafeData, response, 'SafeData'); | ||
| } | ||
|
|
||
| /** | ||
| * Archive the safe. Requires every safe wallet to already be archived; also the abandonment | ||
| * path for a stuck 'initializing' safe. | ||
| */ | ||
| async archive(): Promise<SafeData> { | ||
| const response = await this.bitgo.post(this.url('/archive')).send().result(); | ||
| return decodeWithCodec(SafeData, response, 'SafeData'); | ||
| } | ||
|
|
||
| toJSON(): SafeData { | ||
| return this._safe; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.