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: offer arrange invocation receipt
- Loading branch information
1 parent
9e6324a
commit af70582
Showing
10 changed files
with
226 additions
and
21 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
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,52 @@ | ||
import * as Sentry from '@sentry/serverless' | ||
import { Config } from 'sst/node/config' | ||
|
||
import * as CAR from '@ucanto/transport/car' | ||
|
||
import { connect as ucanLogConnect } from '@spade-proxy/core/ucan-log' | ||
import { offerArrange } from '@spade-proxy/core/arrange-offers' | ||
import { getServiceSigner } from '@spade-proxy/core/service' | ||
|
||
import { mustGetEnv, parseDynamoDbEvent } from '../utils' | ||
|
||
Sentry.AWSLambda.init({ | ||
environment: process.env.SST_STAGE, | ||
dsn: process.env.SENTRY_DSN, | ||
tracesSampleRate: 1.0, | ||
}) | ||
|
||
export async function main(event: import('aws-lambda').DynamoDBStreamEvent) { | ||
const { | ||
spadeProxyDid, | ||
ucanLogUrl | ||
} = getLambdaEnv() | ||
|
||
const records = parseDynamoDbEvent(event) | ||
if (records.length > 1) { | ||
throw new Error('Should only receive one offer to arrange') | ||
} | ||
|
||
// @ts-expect-error can't figure out type of new | ||
const newRecord = unmarshall(records[0].new) | ||
|
||
const { PRIVATE_KEY, UCAN_LOG_BASIC_AUTH } = Config | ||
|
||
const ucanLog = ucanLogConnect({ | ||
url: new URL(ucanLogUrl || ''), | ||
auth: UCAN_LOG_BASIC_AUTH | ||
}) | ||
const serviceSigner = getServiceSigner({ SPADE_PROXY_DID: spadeProxyDid, PRIVATE_KEY }) | ||
|
||
// Create message with receipt from offer arrange | ||
const message = await offerArrange(newRecord, serviceSigner) | ||
|
||
// We block until we can log the UCAN invocation if this fails it will restart | ||
await ucanLog.log(CAR.request.encode(message)) | ||
} | ||
|
||
function getLambdaEnv () { | ||
return { | ||
spadeProxyDid: mustGetEnv('SPADE_PROXY_DID'), | ||
ucanLogUrl: mustGetEnv('UCAN_LOG_URL') | ||
} | ||
} |
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
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
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