-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5cae9cd
commit 305b2d3
Showing
22 changed files
with
657 additions
and
148 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
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 * as UCAN from '@ipld/dag-ucan' | ||
|
||
/** | ||
* Validations | ||
*/ | ||
export class Validations { | ||
/** | ||
* | ||
* @param {KVNamespace} kv | ||
*/ | ||
constructor(kv = VALIDATIONS) { | ||
this.kv = kv | ||
} | ||
|
||
/** | ||
* | ||
* @param {string} delegation | ||
*/ | ||
async create(delegation) { | ||
// @ts-ignore | ||
const ucan = UCAN.parse(delegation) | ||
await this.kv.put(ucan.audience.did(), delegation, { | ||
expirationTtl: 2 * 60, | ||
}) | ||
|
||
return ucan | ||
} | ||
|
||
/** | ||
* @param {string} did | ||
*/ | ||
async get(did) { | ||
const val = await this.kv.get(did) | ||
if (!val) { | ||
throw new Error('Validation not found') | ||
} | ||
|
||
return val | ||
} | ||
|
||
/** | ||
* @param {string} did | ||
*/ | ||
async delete(did) { | ||
await this.kv.delete(did) | ||
} | ||
} |
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,22 @@ | ||
import { Validations } from '../kvs/validations.js' | ||
|
||
/** | ||
* @param {import('@web3-storage/worker-utils/router').ParsedRequest} req | ||
* @param {import('../bindings.js').RouteContext} env | ||
*/ | ||
export async function validate(req, env) { | ||
const validations = new Validations() | ||
if (req.query && req.query.ucan) { | ||
await validations.create(req.query.ucan) | ||
|
||
return new Response('Done') | ||
} | ||
|
||
if (req.query && req.query.did) { | ||
const ucan = await validations.get(req.query.did) | ||
await validations.delete(req.query.did) | ||
return new Response(ucan) | ||
} | ||
|
||
throw new Error('needs ucan or did query') | ||
} |
This file was deleted.
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
Oops, something went wrong.