This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ucanto aggregation api service
- Loading branch information
1 parent
a571bd2
commit 5d8fd55
Showing
11 changed files
with
224 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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,20 @@ | ||
{ | ||
"name": "@spade-proxy/core", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"test": "sst bind vitest", | ||
"typecheck": "tsc -noEmit" | ||
}, | ||
"dependencies": { | ||
"@ipld/dag-ucan": "3.3.2", | ||
"@ucanto/interface": "7.1.0", | ||
"@ucanto/principal": "^7.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.16.3", | ||
"vitest": "^0.31.0", | ||
"sst": "^2.8.3", | ||
"typescript": "^5.0.4" | ||
} | ||
} |
This file contains 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,30 @@ | ||
import * as ed25519 from '@ucanto/principal/ed25519' | ||
import * as DID from '@ipld/dag-ucan/did' | ||
import { Signer } from '@ucanto/interface' | ||
|
||
export const createUcantoServer = (servicePrincipal: Signer, context: UcantoServerCtx) => { | ||
|
||
} | ||
|
||
/** | ||
* Given a config, return a ucanto Signer object representing the service | ||
*/ | ||
export function getServiceSigner(config: ServiceSignerCtx) { | ||
const signer = ed25519.parse(config.PRIVATE_KEY) | ||
if (config.SPADE_PROXY_DID) { | ||
const did = DID.parse(config.SPADE_PROXY_DID).did() | ||
return signer.withDID(did) | ||
} | ||
return signer | ||
} | ||
|
||
export interface UcantoServerCtx { | ||
|
||
} | ||
|
||
export type ServiceSignerCtx = { | ||
// multiformats private key of primary signing key | ||
PRIVATE_KEY: string | ||
// public DID for the upload service (did:key:... derived from PRIVATE_KEY if not set) | ||
SPADE_PROXY_DID: string | ||
} |
This file contains 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,6 @@ | ||
{ | ||
"extends": "@tsconfig/node16/tsconfig.json", | ||
"compilerOptions": { | ||
"module": "esnext" | ||
} | ||
} |
This file contains 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 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,47 @@ | ||
import { Config } from 'sst/node/config' | ||
import { APIGatewayProxyHandlerV2, APIGatewayProxyEventV2 } from 'aws-lambda' | ||
|
||
import { | ||
createUcantoServer, | ||
getServiceSigner | ||
} from '@spade-proxy/core/service' | ||
// TODO: sentry | ||
|
||
async function ucanInvocationRouter(request: APIGatewayProxyEventV2) { | ||
const { | ||
OFFER_BUCKET_NAME: offerBucketName = '', | ||
SPADE_PROXY_DID | ||
} = process.env | ||
|
||
if (!SPADE_PROXY_DID) { | ||
return { | ||
statusCode: 500, | ||
} | ||
} else if (request.body === undefined) { | ||
return { | ||
statusCode: 400, | ||
} | ||
} | ||
|
||
const { PRIVATE_KEY } = Config | ||
const serviceSigner = getServiceSigner({ SPADE_PROXY_DID, PRIVATE_KEY }) | ||
const server = await createUcantoServer(serviceSigner, {}) | ||
|
||
return { | ||
statusCode: 200, | ||
// TODO | ||
} | ||
} | ||
|
||
export const handler: APIGatewayProxyHandlerV2 = async (event) => { | ||
return ucanInvocationRouter(event) | ||
} | ||
|
||
// would be generated by sst, but requires `sst build` to be run, which calls out to aws; not great for CI | ||
declare module 'sst/node/config' { | ||
export interface SecretResources { | ||
PRIVATE_KEY: { | ||
value: string | ||
} | ||
} | ||
} |
This file contains 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 @@ | ||
/// <reference path="../../.sst/types/index.ts" /> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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,17 @@ | ||
import { Bucket, StackContext } from 'sst/constructs'; | ||
|
||
import { getBucketConfig } from './config'; | ||
|
||
export function DataStack({ stack }: StackContext) { | ||
const bucket = getBucketConfig('offer-store', stack.stage) | ||
const offerBucket = new Bucket(stack, bucket.bucketName, { | ||
cors: true, | ||
cdk: { | ||
bucket | ||
} | ||
}) | ||
|
||
return { | ||
offerBucket | ||
} | ||
} |