Skip to content

Commit

Permalink
fix: add support for did:web in the cli (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias authored Dec 14, 2022
1 parent b538082 commit a1f9e85
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
1 change: 0 additions & 1 deletion packages/access-api/scripts/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ prog
const mf = new Miniflare({
packagePath: true,
wranglerConfigPath: true,
wranglerConfigEnv: 'dev',
sourceMap: true,
modules: true,
watch: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/access-api/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Development
name = "w3access-test"
name = "w3access-local"
account_id = "fffa4b4363a7e5250af8357087263b3a"
main = "./dist/worker.js"

Expand Down
24 changes: 19 additions & 5 deletions packages/access-client/src/cli/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-ignore
// eslint-disable-next-line no-unused-vars
import * as Ucanto from '@ucanto/interface'
import { Verifier } from '@ucanto/principal/ed25519'
import { DID } from '@ucanto/core'
import inquirer from 'inquirer'

/** @type {Record<string,string>} */
Expand All @@ -12,6 +12,13 @@ const envs = {
local: 'http://127.0.0.1:8787',
}

/** @type {Record<string,string>} */
const dids = {
production: 'did:web:web3.storage',
staging: 'did:web:staging.web3.storage',
dev: 'did:web:dev.web3.storage',
}

/**
* @type {import("@ucanto/interface").Principal}
*/
Expand All @@ -22,14 +29,21 @@ let audience
*/
export async function getService(env) {
const url = new URL(envs[env])
let did

if (audience) {
return { url, did: audience }
return { url, servicePrincipal: audience }
} else {
const rsp = await fetch(url + 'version')
if (env === 'local') {
const rsp = await fetch(url + 'version')
const data = await rsp.json()
did = data.did
} else {
did = dids[env]
}

// @ts-ignore
const { did } = await rsp.json()
audience = Verifier.parse(did)
audience = DID.parse(did)
return { url, servicePrincipal: audience }
}
}
Expand Down

0 comments on commit a1f9e85

Please sign in to comment.