-
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.
- feat: Add optional origin to store/add (#73) Co-authored-by: Hugo Dias <hugomrdias@gmail.com> Co-authored-by: ice.breaker <94936890+ice-breaker-tg@users.noreply.github.com>
- Loading branch information
1 parent
6a7ea62
commit 9f6cb41
Showing
65 changed files
with
2,406 additions
and
1,497 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ node_modules | |
# testing | ||
coverage | ||
.nyc_output | ||
.wrangler | ||
|
||
|
||
# misc | ||
|
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,11 @@ | ||
DROP TABLE IF EXISTS accounts; | ||
|
||
CREATE TABLE accounts ( | ||
did TEXT NOT NULL PRIMARY KEY | ||
, product TEXT NOT NULL | ||
, email TEXT NOT NULL | ||
, agent TEXT NOT NULL | ||
, inserted_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) | ||
, updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) | ||
, UNIQUE(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
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,15 @@ | ||
/** | ||
* @param {import('@web3-storage/worker-utils/router').ParsedRequest} req | ||
* @param {import('../bindings.js').RouteContext} env | ||
*/ | ||
export async function validateEmail(req, env) { | ||
if (req.query && req.query.ucan && req.query.did) { | ||
// TODO parse and set KV ttl to delegation ttl | ||
|
||
await env.config.VALIDATIONS.put(req.query.did, req.query.ucan) | ||
|
||
return new Response('Done') | ||
} | ||
|
||
throw new Error('needs ucan or did query') | ||
} |
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,63 @@ | ||
import pRetry from 'p-retry' | ||
|
||
const run = async ( | ||
/** @type {KVNamespace<string>} */ kv, | ||
/** @type {WebSocket} */ server, | ||
/** @type {any} */ did | ||
) => { | ||
const d = await kv.get(did) | ||
|
||
if (!d) { | ||
throw new Error('Not found.') | ||
} else { | ||
server.send( | ||
JSON.stringify({ | ||
type: 'delegation', | ||
delegation: d, | ||
}) | ||
) | ||
server.close() | ||
await kv.delete(did) | ||
return d | ||
} | ||
} | ||
|
||
/** | ||
* @param {import('@web3-storage/worker-utils/router').ParsedRequest} req | ||
* @param {import('../bindings.js').RouteContext} env | ||
*/ | ||
export async function validateWS(req, env) { | ||
const upgradeHeader = req.headers.get('Upgrade') | ||
if (!upgradeHeader || upgradeHeader !== 'websocket') { | ||
return new Response('Expected Upgrade: websocket', { status: 426 }) | ||
} | ||
|
||
const [client, server] = Object.values(new WebSocketPair()) | ||
server.accept() | ||
server.addEventListener('message', async (msg) => { | ||
// @ts-ignore | ||
const { did } = JSON.parse(msg.data) | ||
|
||
try { | ||
await pRetry(() => run(env.config.VALIDATIONS, server, did), { | ||
retries: 200, | ||
minTimeout: 1000, | ||
factor: 1, | ||
}) | ||
} catch (error) { | ||
const err = /** @type {Error} */ (error) | ||
server.send( | ||
JSON.stringify({ | ||
type: 'timeout', | ||
error: err.message, | ||
}) | ||
) | ||
server.close() | ||
} | ||
}) | ||
|
||
return new Response(undefined, { | ||
status: 101, | ||
webSocket: client, | ||
}) | ||
} |
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.