-
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.
- Loading branch information
Wes Biggs
committed
Nov 10, 2023
0 parents
commit ebc6573
Showing
13 changed files
with
7,910 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# /node_modules/* in the project root is ignored by default | ||
/dist | ||
/*.map |
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,67 @@ | ||
{ | ||
"env": { | ||
"browser": false, | ||
"node": true | ||
}, | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { "project": ["./tsconfig.eslint.json"] }, | ||
"plugins": [ | ||
"@typescript-eslint", | ||
"prettier", | ||
"jest", | ||
"import" | ||
], | ||
"extends": [ | ||
"eslint:recommended", | ||
"prettier" | ||
], | ||
"rules": { | ||
"semi": [ | ||
"error", | ||
"always" | ||
], | ||
"quotes": [ | ||
"error", | ||
"double", | ||
{ | ||
"avoidEscape": true | ||
} | ||
], | ||
"import/extensions": ["error", "always", { "ignorePackages": true } ], | ||
"mocha/no-setup-in-describe": "off", | ||
"prettier/prettier": "error", | ||
"no-use-before-define": "off", | ||
"no-unused-vars": "off", | ||
"no-var": "error", | ||
"id-length": [ | ||
"error", | ||
{ | ||
"exceptionPatterns": [ | ||
"[i-k]", | ||
"c", | ||
"e", | ||
"n", | ||
"p", | ||
"r", | ||
"s", | ||
"v", | ||
"x", | ||
"y" | ||
], | ||
"properties": "never" | ||
} | ||
], | ||
"allow-namespace": "off", | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"**/*.test.ts", | ||
"**/*.spec.ts" | ||
], | ||
"env": { | ||
"jest": true | ||
} | ||
} | ||
] | ||
} |
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,130 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
web_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
.stylelintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
.temp | ||
.cache | ||
|
||
# Docusaurus cache and generated files | ||
.docusaurus | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
|
||
# yarn v2 | ||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* |
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,56 @@ | ||
# Overview | ||
|
||
This package contains a plugin for the [@dsnp/did-resolver](https://github.com/LibertyDSNP/dsnp-did-resolver) library which enables resolution of `did:dsnp:*` DIDs using the [Frequency](https://github.com/LibertyDSNP/frequency) blockchain. | ||
|
||
# Usage | ||
|
||
``` | ||
import "@amplica-labs/dsnp-did-resolver-plugin-frequency"; | ||
``` | ||
|
||
The plugin will automatically register itself with the DSNP DID resolver when imported. | ||
|
||
Here's a full usage example with the DID resolver framework: | ||
|
||
``` | ||
import { Resolver } from "did-resolver"; | ||
import dsnp from "@dsnp/did-resolver"; | ||
import "@amplica-labs/dsnp-did-resolver-plugin-frequency"; | ||
const resolver = new Resolver(dsnp.getResolver()); | ||
const myDid = "did:dsnp:123456"; | ||
const result = await resolver.resolve(myDid); | ||
console.log(JSON.stringify(result, null, 2)); | ||
/* Example output: | ||
{ | ||
"didResolutionMetadata": { | ||
"contentType": "application/did+ld+json" | ||
}, | ||
"didDocument": { | ||
"@context": [ | ||
"https://www.w3.org/ns/did/v1" | ||
], | ||
"id": "did:dsnp:123456", | ||
"assertionMethod": [ | ||
{ | ||
"@context": [ | ||
"https://w3id.org/security/multikey/v1" | ||
], | ||
"id": "did:dsnp:123456#z6MkuzE4hBVHTmwFff37ZuPQs9sbkdJo8jifN9sZ1jXbgyMp", | ||
"type": "Multikey", | ||
"controller": "did:dsnp:123456", | ||
"publicKeyMultibase": "z6MkuzE4hBVHTmwFff37ZuPQs9sbkdJo8jifN9sZ1jXbgyMp" | ||
} | ||
] | ||
}, | ||
"didDocumentMetadata": {} | ||
} | ||
*/ | ||
``` | ||
|
||
# Features | ||
|
||
Currently this plugin implements the minimal functionality to support using keys associated with a DSNP User Id to verify Verifiable Credentials. | ||
|
||
- DSNP public keys with `keyType` 2 are listed in the `assertionMethod` array using the `Multikey` type. The `id` fragment is the same as the `publicKeyMultibase` value, which is a multicodec value in `base58btc` encoding. The decoded value for `ed25519-pub` keys will be 34 bytes, including the two-byte multicodec identifier. |
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 @@ | ||
declare module "avro-js"; |
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,70 @@ | ||
import { options } from "@frequency-chain/api-augment"; | ||
import { WsProvider, ApiPromise } from "@polkadot/api"; | ||
|
||
// Environment Variables | ||
const providerUri = process.env.FREQUENCY_NODE; | ||
const frequencyNetwork = process.env.FREQUENCY_NETWORK; | ||
|
||
if (!providerUri) { | ||
throw new Error("FREQUENCY_NODE env variable is required"); | ||
} | ||
|
||
if ( | ||
!frequencyNetwork || | ||
!["local", "testnet", "mainnet"].includes(frequencyNetwork) | ||
) { | ||
throw new Error( | ||
'FREQUENCY_NETWORK env variable must be one of: "local", "testnet", "mainnet"', | ||
); | ||
} | ||
|
||
export const getNetwork = () => | ||
frequencyNetwork as "local" | "testnet" | "mainnet"; | ||
|
||
// Reset | ||
export const disconnectApi = async () => { | ||
if (_singletonApi === null) return; | ||
|
||
const api = await getApi(); | ||
await api.disconnect(); | ||
_singletonApi = null; | ||
return; | ||
}; | ||
|
||
let _singletonApi: null | Promise<ApiPromise> = null; | ||
|
||
export const getApi = (): Promise<ApiPromise> => { | ||
if (_singletonApi !== null) { | ||
return _singletonApi; | ||
} | ||
|
||
if (!providerUri) { | ||
throw new Error("FREQUENCY_NODE env variable is required"); | ||
} | ||
|
||
const provider = new WsProvider(providerUri); | ||
_singletonApi = ApiPromise.create({ | ||
provider, | ||
throwOnConnect: true, | ||
...options, | ||
}); | ||
|
||
return _singletonApi; | ||
}; | ||
|
||
export enum ChainType { | ||
Local, | ||
Testnet, | ||
Mainnet, | ||
} | ||
|
||
export const getChainType = (): ChainType => { | ||
switch (getNetwork()) { | ||
case "local": | ||
return ChainType.Local; | ||
case "testnet": | ||
return ChainType.Testnet; | ||
case "mainnet": | ||
return ChainType.Mainnet; | ||
} | ||
}; |
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,27 @@ | ||
import "dotenv/config"; | ||
import { getResolver } from "@dsnp/did-resolver"; | ||
import { Resolver } from "did-resolver"; | ||
import { expect, jest, test } from "@jest/globals"; | ||
import "./index.js"; | ||
import { disconnectApi } from "./frequency.js"; | ||
|
||
jest.setTimeout(15000); | ||
|
||
describe("dsnp-did-resolver", () => { | ||
let resolver: Resolver; | ||
|
||
beforeAll(() => { | ||
resolver = new Resolver(getResolver()); | ||
}); | ||
|
||
test("Resolve did:dsnp:13972", async () => { | ||
const myDid = "did:dsnp:13972"; | ||
const result = await resolver.resolve(myDid); | ||
console.log(JSON.stringify(result, null, 2)); | ||
}); | ||
|
||
afterAll(() => { | ||
// Shut down Frequency client | ||
disconnectApi(); | ||
}); | ||
}); |
Oops, something went wrong.