Skip to content

Commit 3996532

Browse files
committed
configurable custody service
1 parent b0334ed commit 3996532

28 files changed

+568
-382
lines changed

.changeset/slick-bugs-admire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@penumbra-zone/services': major
3+
---
4+
5+
custody context now requires the host to provide a complete implementation

packages/services/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,25 @@
2323
"types": "./dist/ctx/*.d.ts",
2424
"default": "./dist/ctx/*.js"
2525
},
26+
"./validation/*": {
27+
"types": "./dist/validation/*.d.ts",
28+
"default": "./dist/validation/*.js"
29+
},
2630
"./*": {
2731
"types": "./dist/*/index.d.ts",
2832
"default": "./dist/*/index.js"
2933
}
3034
},
35+
"dependencies": {
36+
"@penumbra-zone/keys": "workspace:*"
37+
},
3138
"devDependencies": {
3239
"@bufbuild/protobuf": "^1.10.0",
3340
"@connectrpc/connect": "^1.6.1",
3441
"@penumbra-zone/bech32m": "workspace:*",
35-
"@penumbra-zone/crypto-web": "workspace:*",
3642
"@penumbra-zone/getters": "workspace:*",
3743
"@penumbra-zone/protobuf": "workspace:*",
3844
"@penumbra-zone/storage": "workspace:*",
39-
"@penumbra-zone/transport-dom": "workspace:*",
4045
"@penumbra-zone/types": "workspace:*",
4146
"@penumbra-zone/wasm": "workspace:*",
4247
"@types/chrome": "^0.0.268"
@@ -45,11 +50,8 @@
4550
"@bufbuild/protobuf": "^1.10.0",
4651
"@connectrpc/connect": "^1.6.1",
4752
"@penumbra-zone/bech32m": "workspace:*",
48-
"@penumbra-zone/crypto-web": "workspace:*",
4953
"@penumbra-zone/getters": "workspace:*",
5054
"@penumbra-zone/protobuf": "workspace:*",
51-
"@penumbra-zone/storage": "workspace:*",
52-
"@penumbra-zone/transport-dom": "workspace:*",
5355
"@penumbra-zone/types": "workspace:*",
5456
"@penumbra-zone/wasm": "workspace:*"
5557
}

packages/services/src/ctx/approver.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Code, ConnectError, createContextKey } from '@connectrpc/connect';
2+
import {
3+
AuthorizationData,
4+
TransactionPlan,
5+
} from '@penumbra-zone/protobuf/penumbra/core/transaction/v1/transaction_pb';
6+
7+
/** Authorizes a transaction plan. */
8+
export const authorizePlanCtx = createContextKey<
9+
(plan: TransactionPlan, signal: AbortSignal) => Promise<AuthorizationData>
10+
>(
11+
/** A stub implementation that always throws an error. */
12+
() => Promise.reject(new ConnectError('Default plan authorization stub', Code.Unimplemented)),
13+
{ description: 'Authorizes a transaction plan' },
14+
);
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { ContextKey, createContextKey, Client } from '@connectrpc/connect';
22
import type { CustodyService } from '@penumbra-zone/protobuf';
33

4-
export const custodyClientCtx: ContextKey<Client<typeof CustodyService> | undefined> =
5-
createContextKey(undefined);
4+
export const custodyClientCtx: ContextKey<Client<typeof CustodyService>> = createContextKey(
5+
null as never,
6+
{ description: 'View service may call the custody service for authorizations' },
7+
);
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Code, ConnectError, createContextKey } from '@connectrpc/connect';
22
import { FullViewingKey } from '@penumbra-zone/protobuf/penumbra/core/keys/v1/keys_pb';
33

4-
export const fvkCtx = createContextKey<() => Promise<FullViewingKey>>(() =>
5-
Promise.reject(new ConnectError('No full viewing key available', Code.FailedPrecondition)),
4+
export const fvkCtx = createContextKey<() => Promise<FullViewingKey>>(
5+
/** A stub implementation that always throws an error. */
6+
() => Promise.reject(new ConnectError('Default full viewing key stub', Code.Unimplemented)),
7+
{ description: 'View service requires a full viewing key' },
68
);

packages/services/src/ctx/prax.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* portable service implementations, should eventually be refactored.
44
*/
55

6-
import { ConnectError, createContextKey } from '@connectrpc/connect';
6+
import { createContextKey } from '@connectrpc/connect';
77
import type { ServicesInterface } from '@penumbra-zone/types/services';
88

9-
export const servicesCtx = createContextKey<() => Promise<ServicesInterface>>(() =>
10-
Promise.reject(new ConnectError('No prax services interface available')),
11-
);
9+
export const servicesCtx = createContextKey<() => Promise<ServicesInterface>>(null as never, {
10+
description: 'A random collection of interfaces',
11+
});

packages/services/src/ctx/spend-key.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { ContextKey, createContextKey, Client } from '@connectrpc/connect';
22
import type { StakeService } from '@penumbra-zone/protobuf';
33

4-
export const stakeClientCtx: ContextKey<Client<typeof StakeService> | undefined> =
5-
createContextKey(undefined);
4+
export const stakeClientCtx: ContextKey<Client<typeof StakeService>> = createContextKey(
5+
null as never,
6+
{ description: 'View service may call the stake service for delegation info' },
7+
);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { PartialMessage } from '@bufbuild/protobuf';
2+
import { createContextKey, ConnectError, Code } from '@connectrpc/connect';
3+
import { TransactionPlan } from '@penumbra-zone/protobuf/penumbra/core/transaction/v1/transaction_pb';
4+
5+
/** Validates a transaction plan. */
6+
export const validatePlanCtx = createContextKey<
7+
(plan?: PartialMessage<TransactionPlan>, signal?: AbortSignal) => Promise<TransactionPlan>
8+
>(
9+
/** A stub implementation that always throws an error. */
10+
() => Promise.reject(new ConnectError('Default plan validation stub', Code.Unimplemented)),
11+
{ description: 'Validates a transaction plan.' },
12+
);

0 commit comments

Comments
 (0)