-
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
4
commits 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
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3e92d39
feat: add sdk-core vault module interfaces and scaffolding
davidkaplanbitgo 06f2597
chore: add Pr review comments
davidkaplanbitgo 7da4e23
feat: nest vault keys under walletType
davidkaplanbitgo 2fd4e03
feat: rename vault to safe
davidkaplanbitgo 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
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't these live in a shared package? doesn't the backend use the same types? |
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,200 @@ | ||
| /** | ||
| * @prettier | ||
| * | ||
| * io-ts codecs for the safe REST surface. These are the single source of truth for the | ||
| * safe data shapes: the TypeScript interfaces in `iSafe.ts` are derived from them via | ||
| * `t.TypeOf`, request bodies are encoded with `postWithCodec`, and responses are decoded | ||
| * (and validated) with `decodeWithCodec` — so there are no `as SafeData` casts. | ||
| * | ||
| * Timestamps use `DateFromISOString`: the wire representation stays an ISO-8601 string while | ||
| * the decoded object exposes a real `Date`. | ||
| */ | ||
| import * as t from 'io-ts'; | ||
| import { DateFromISOString } from 'io-ts-types'; | ||
|
|
||
| /** | ||
| * The four static root-key slots of a safe, keyed by (curve, scheme): | ||
| * - secp256k1Multisig ① — ex. UTXO/XRP/XTZ/TRX/EOS | ||
| * - ecdsaMpc ② — ex. EVM/Cosmos (DKLS) | ||
| * - eddsaMpc ③ — ex. SOL/SUI/NEAR/TON/APT/DOT | ||
| * - ed25519Multisig ④ — ex. ALGO/XLM/HBAR | ||
| */ | ||
| export const RootKeyType = t.keyof( | ||
| { | ||
| secp256k1Multisig: null, | ||
| ecdsaMpc: null, | ||
| eddsaMpc: null, | ||
| ed25519Multisig: null, | ||
| }, | ||
| 'RootKeyType' | ||
| ); | ||
|
|
||
| export const SafePermission = t.keyof( | ||
| { | ||
| view: null, | ||
| spend: null, | ||
| admin: null, | ||
| dapp: null, | ||
| }, | ||
| 'SafePermission' | ||
| ); | ||
|
|
||
| /** An ordered [userKeyId, backupKeyId, bitgoKeyId] triplet — same shape/order as wallet.keys[]. */ | ||
| export const RootKeyTriplet = t.tuple([t.string, t.string, t.string], 'RootKeyTriplet'); | ||
|
|
||
| /** The 12 root key ids for a single custody model, keyed by (curve, scheme). */ | ||
| export const RootKeysByType = t.type( | ||
| { | ||
| secp256k1Multisig: RootKeyTriplet, | ||
| ecdsaMpc: RootKeyTriplet, | ||
| eddsaMpc: RootKeyTriplet, | ||
| ed25519Multisig: RootKeyTriplet, | ||
| }, | ||
| 'RootKeysByType' | ||
| ); | ||
|
|
||
| /** Custody models a safe's roots can be created under. v1 implements `hot` only. */ | ||
| export const SafeCustodyType = t.keyof( | ||
| { | ||
| hot: null, | ||
| cold: null, | ||
| custodial: null, | ||
| }, | ||
| 'SafeCustodyType' | ||
| ); | ||
|
|
||
| /** | ||
| * A safe's root keys grouped by custody model — each model holds its own set of 4 (curve, scheme) | ||
| * root triplets. Only `hot` is populated in v1; `cold`/`custodial` are reserved for later phases. | ||
| */ | ||
| export const SafeRootKeys = t.partial( | ||
| { | ||
| hot: RootKeysByType, | ||
| cold: RootKeysByType, | ||
| custodial: RootKeysByType, | ||
| }, | ||
| 'SafeRootKeys' | ||
| ); | ||
|
|
||
| export const SafeMembershipData = t.intersection( | ||
| [ | ||
| t.type({ | ||
| userId: t.string, | ||
| permissions: t.array(SafePermission), | ||
| }), | ||
| t.partial({ | ||
| needsRecovery: t.boolean, | ||
| }), | ||
| ], | ||
| 'SafeMembershipData' | ||
| ); | ||
|
|
||
| /** A pending UMS spend grant awaiting a key share — mirror of the wallet's walletShareRequests[]. */ | ||
| export const SafeShareRequest = t.type( | ||
| { | ||
| userId: t.string, | ||
| permissions: t.array(SafePermission), | ||
| createdAt: DateFromISOString, | ||
| }, | ||
| 'SafeShareRequest' | ||
| ); | ||
|
|
||
| export const SafeFreeze = t.partial( | ||
| { | ||
| time: DateFromISOString, | ||
| expires: DateFromISOString, | ||
| reason: t.string, | ||
| }, | ||
| 'SafeFreeze' | ||
| ); | ||
|
|
||
| export const SafeStatus = t.keyof( | ||
| { | ||
| initializing: null, | ||
| active: null, | ||
| archived: null, | ||
| }, | ||
| 'SafeStatus' | ||
| ); | ||
|
|
||
| export const SafeData = t.intersection( | ||
| [ | ||
| t.type({ | ||
| id: t.string, | ||
| enterpriseId: t.string, | ||
| label: t.string, | ||
| status: SafeStatus, | ||
| creator: t.string, | ||
| users: t.array(SafeMembershipData), | ||
| createdAt: DateFromISOString, | ||
| }), | ||
| t.partial({ | ||
| safeShareRequests: t.array(SafeShareRequest), | ||
| freeze: SafeFreeze, | ||
| rootKeys: SafeRootKeys, | ||
| archivedAt: DateFromISOString, | ||
| }), | ||
| ], | ||
| 'SafeData' | ||
| ); | ||
|
|
||
| /** Safe key-share states — identical to WalletShare states, no new states. */ | ||
| export const SafeShareState = t.keyof( | ||
| { | ||
| pendingapproval: null, | ||
| active: null, | ||
| accepted: null, | ||
| canceled: null, | ||
| rejected: null, | ||
| }, | ||
| 'SafeShareState' | ||
| ); | ||
|
|
||
| /** One of the 4 root USER keyshares carried on a SafeShare, ECDH-re-encrypted to the recipient. */ | ||
| export const SafeShareKeychain = t.type( | ||
| { | ||
| rootKeyType: RootKeyType, | ||
| rootKeyId: t.string, | ||
| encryptedPrv: t.string, | ||
| publicIdentifier: t.string, | ||
| fromPubKey: t.string, | ||
| toPubKey: t.string, | ||
| path: t.string, | ||
| }, | ||
| 'SafeShareKeychain' | ||
| ); | ||
|
|
||
| export const SafeShareData = t.intersection( | ||
| [ | ||
| t.type({ | ||
| id: t.string, | ||
| enterpriseId: t.string, | ||
| safeId: t.string, | ||
| fromUser: t.string, | ||
| toUser: t.string, | ||
| permissions: t.array(SafePermission), | ||
| state: SafeShareState, | ||
| createdAt: DateFromISOString, | ||
| }), | ||
| t.partial({ | ||
| safeLabel: t.string, | ||
| message: t.string, | ||
| pendingApprovalId: t.string, | ||
| isUMSInitiated: t.boolean, | ||
| keychains: t.array(SafeShareKeychain), | ||
| updatedAt: DateFromISOString, | ||
| }), | ||
| ], | ||
| 'SafeShareData' | ||
| ); | ||
|
|
||
| // ---- request bodies ---- | ||
|
|
||
| /** POST /enterprise/:eId/safes — Phase 1 carries no key material. */ | ||
| export const InitializeSafeBody = t.type({ label: t.string }, 'InitializeSafeBody'); | ||
|
|
||
| /** POST /enterprise/:eId/safes/:safeId/finalize — the 12 key ids as 4 ordered triplets. */ | ||
| export const FinalizeSafeBody = t.type({ rootKeys: SafeRootKeys }, 'FinalizeSafeBody'); | ||
|
|
||
| /** POST /enterprise/:eId/safes/:safeId/freeze */ | ||
| export const FreezeSafeBody = t.partial({ duration: t.number }, 'FreezeSafeBody'); |
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,102 @@ | ||
| /** | ||
| * @prettier | ||
| * | ||
| * @experimental The safe client surface is experimental and may change (including breaking | ||
| * changes) before the public release. | ||
| */ | ||
| import * as t from 'io-ts'; | ||
| import type { FreezeOptions, Wallet, WalletShare } from '../wallet'; | ||
| import * as SafeCodecs from './codecs'; | ||
|
|
||
| // ---- data shapes (derived from the io-ts codecs in ./codecs — single source of truth) ---- | ||
|
|
||
| export type RootKeyType = t.TypeOf<typeof SafeCodecs.RootKeyType>; | ||
| export type SafePermission = t.TypeOf<typeof SafeCodecs.SafePermission>; | ||
| export type SafeCustodyType = t.TypeOf<typeof SafeCodecs.SafeCustodyType>; | ||
| export type RootKeysByType = t.TypeOf<typeof SafeCodecs.RootKeysByType>; | ||
| export type SafeRootKeys = t.TypeOf<typeof SafeCodecs.SafeRootKeys>; | ||
| export type SafeMembershipData = t.TypeOf<typeof SafeCodecs.SafeMembershipData>; | ||
| export type SafeShareRequest = t.TypeOf<typeof SafeCodecs.SafeShareRequest>; | ||
| export type SafeData = t.TypeOf<typeof SafeCodecs.SafeData>; | ||
| export type SafeShareState = t.TypeOf<typeof SafeCodecs.SafeShareState>; | ||
| export type SafeShareKeychain = t.TypeOf<typeof SafeCodecs.SafeShareKeychain>; | ||
| export type SafeShareData = t.TypeOf<typeof SafeCodecs.SafeShareData>; | ||
|
|
||
| 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?: FreezeOptions): Promise<SafeData>; | ||
| archive(): Promise<SafeData>; | ||
| toJSON(): SafeData; | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my understanding is that the name should be "Vaults" not "Safes"