Git Product home page Git Product logo

dwn-sdk-js's Introduction

well-known files for universal links to TBD projects

dwn-sdk-js's People

Contributors

0scvr avatar alexlemons avatar amika-sq avatar angiejones avatar annmalavet avatar blackgirlbytes avatar csuwildcat avatar cxxshyy avatar dcrousso avatar diehuxx avatar duncanmak avatar ebonylouis avatar flothjl avatar frankhinek avatar grahnj avatar gtaylor5 avatar kirahsapong avatar lirancohen avatar michaelneale avatar mistermoe avatar nearlyjuly avatar rajakash-dev avatar shamilovtim avatar shobitb avatar thehenrytsai avatar theisens avatar timotheemm avatar virajjiwane avatar vlad-timofeev avatar wavesrcool avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dwn-sdk-js's Issues

Replace publicKeyJwk validation with JSON Schema based validation

Replace publicKeyJwk validation with JSON Schema-based validation

dwn-sdk-js/src/message.ts

Lines 146 to 151 in 98202be

// TODO: replace with JSON Schema based validation
// more info about the `publicKeyJwk` property can be found here:
// https://www.w3.org/TR/did-spec-registries/#publickeyjwk
if (!publicKeyJwk) {
throw new Error(`publicKeyJwk property not found on verification method [${kid}]`);
}

Replace verificationMethod checks with JSON Schema based validation (JsonWebKey2020)

Replace with JSON Schema based validation for JsonWebKey2020. More info about the JsonWebKey2020 type can be found here: https://www.w3.org/TR/did-spec-registries/#jsonwebkey2020

// TODO: replace with JSON Schema based validation
// more info about the `JsonWebKey2020` type can be found here:
// https://www.w3.org/TR/did-spec-registries/#jsonwebkey2020
if (verificationMethod.type !== 'JsonWebKey2020') {
throw new Error(`verification method [${kid}] must be JsonWebKey2020`);
}

Clean up code and make composable

Clean this up and likely move it elsewhere (e.g. a different function) so that it can be used elsewhere

const indexDocument: any = { _id: encodedBlock.cid.toString(), method, objectId };
// TODO: clean this up and likely move it elsewhere (e.g. a different function) so that it can be used elsewhere
if (descriptor.method === 'PermissionsRequest') {
indexDocument.ability = descriptor.ability;
indexDocument.requester = descriptor.requester;
}
await this.index.PUT([indexDocument]);

Check controller and DID in kid are the same

Figure out if we need to check to ensure that controller === did in kid are the same. This may matter more for a PermissionsRequest

dwn-sdk-js/src/message.ts

Lines 150 to 154 in 98202be

throw new Error(`publicKeyJwk property not found on verification method [${kid}]`);
}
// TODO: figure out if we need to check to ensure that `controller` === did in kid
// are the same. This may matter more for a `PermissionsRequest`

Decide on how we want to handle errors

Currently all we do is Throw new Error all over the place, and that may or may not be the path we want to stick with moving forward. Use this issue as a means to discuss pros/cons of different approaches for handling errors

Add docs to `dwn.ts`

Add docs to dwn.ts processMessage(rawMessage: object, ctx: Context)

dwn-sdk-js/src/dwn.ts

Lines 82 to 88 in fcea849

/**
* TODO: add docs
* @param message
*/
async processMessage(rawMessage: object, ctx: Context): Promise<MessageReply> {
let message: MessageSchema;

Add better DID validation

Current requester DID validation uses naive technique. Add better DID validation.

public async resolve(did: string): Promise<DIDResolutionResult> {
// naively validate requester DID
// TODO: add better DID validation
const splitDID = did.split(':', 3);
if (splitDID.length < 3) {
throw new Error(`${did} is not a valid DID`);
}

Proposed changes in PR #60. New function validateDID(did):

public async resolve(did: string): Promise<DIDResolutionResult> {
// naively validate requester DID
validateDID(did);
const splitDID = did.split(':', 3);

Function implementation:

/**
* @param did - the DID to validate
*/
export function validateDID(did: unknown): void {
// @see https://www.w3.org/TR/2021/PR-did-core-20210803/#did-syntax
const DID_REGEX = /^did:[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+:[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+$/;
if (typeof did !== 'string') {
throw new TypeError(`DID is not string: ${did}`);
}
if (!DID_REGEX.test(did)) {
throw new TypeError(`DID is not a valid DID: ${did}`);
}
}

Add cache support to avoid costly validation of the same signature

Add logic to prevent validating duplicate signatures

// TODO: add logic to prevent validating duplicate signatures
export class GeneralJwsVerifier {
jws: GeneralJws;
constructor(jws: GeneralJws) {
this.jws = jws;
}
async verify(didResolver: DIDResolver): Promise<VerificationResult> {
const signers: string[] = [];
for (const signature of this.jws.signatures) {
const protectedBytes = base64url.baseDecode(signature.protected);
const protectedJson = new TextDecoder().decode(protectedBytes);
const { kid } = JSON.parse(protectedJson);
const did = GeneralJwsVerifier.extractDid(kid);
const publicJwk = await GeneralJwsVerifier.getPublicKey(did, kid, didResolver);
const isVerified = await GeneralJwsVerifier.verifySignature(this.jws.payload, signature, publicJwk);
if (isVerified) {
signers.push(did);
} else {
throw new Error(`signature verification failed for ${did}`);
}
}
return { signers };
}

Paramaterize name in message-store-level.ts

Calling searchIndex twice causes the process to hang, so check to see if the index has already been "opened" before opening it again.

async open(): Promise<void> {
await this.db.open();
// TODO: look into using the same level we're using for blockstore
// TODO: parameterize `name`
// calling `searchIndex` twice causes the process to hang, so check to see if the index
// has already been "opened" before opening it again.
if (!this.index) {
this.index = await searchIndex({ name: this.config.indexLocation });
}
}

Build helpful errors object using returned errors

  • Every time a validation function is called the errors property is overwritten.
    eg const errors = [...validateFn.errors];

if (!isValid) {
// TODO: build helpful errors object using returned errors
// Every time a validation function is called the errors property is overwritten.
// const errors = [...validateFn.errors];
throw new Error('Invalid message.');
}
}

Workaround for search-indexlib not importing type

Find a workaround for search-indexlib not importing type SearchIndex

export class MessageStoreLevel implements MessageStore {
config: MessageStoreLevelConfig;
db: BlockstoreLevel;
// levelDB doesn't natively provide the querying capabilities needed for DWN. To accommodate, we're leveraging
// a level-backed inverted index
// TODO: search-index lib does not import type `SearchIndex`. find a workaround
index;

Figure out if support needed for all W3 verification method properties

Figure out if we need to support ALL verification method properties.

// TODO: figure out if we need to support ALL verification method properties
// listed here: https://www.w3.org/TR/did-spec-registries/#verification-method-properties
export type VerificationMethod = {
id: string
// one of the valid verification method types as per
// https://www.w3.org/TR/did-spec-registries/#verification-method-types
type: string
// DID of the key's controller
controller: string
// a JSON Web Key that conforms to https://datatracker.ietf.org/doc/html/rfc7517
publicKeyJwk?: PublicJwk
// a string representation of
// https://datatracker.ietf.org/doc/html/draft-multiformats-multibase-05
publicKeyMultibase?: string
};

Add support for `EdDSA` and `ES256K` key types in the browser.

JOSE doesn't support EdDSA or ES256K (aka secp256k1) in the browser. I went ahead and added automated headless browser testing against our browser bundles so that we can fish out issues like these programmatically.

The tests that generate EdDSA keys are currently failing in the browser.

Replace verificationMethod checks with JSON Schema based validation (publicJwk)

Replace with JSON Schema based validation for publicJwk. More info about the publicJwk property can be found here: https://www.w3.org/TR/did-spec-registries/#publicJwk

const { publicKeyJwk: publicJwk } = verificationMethod;
// TODO: replace with JSON Schema based validation
// more info about the `publicJwk` property can be found here:
// https://www.w3.org/TR/did-spec-registries/#publicJwk
if (!publicJwk) {
throw new Error(`publicKeyJwk property not found on verification method [${kid}]`);
}
return publicJwk as PublicJwk;
}

Update Markdown-based doc links to absolute from relative

As required for surfacing documentation on Developer Site

Starting point for request:

https://github.com/TBD54566975/dwn-sdk-js/blob/main/CONTRIBUTING.md
Link to : .eslintrc.cjs should be fully qualified (https://github.com/TBD54566975/dwn-sdk-js/blob/main/.eslintrc.cjs)
https://github.com/TBD54566975/dwn-sdk-js/blob/main/GOVERNANCE.md
Broken links:
[List of maintainers - MAINTAINERS.md](https://github.com/TBD54566975/dwn-sdk-js/blob/main/MAINTAINERS.md)

Use the same level for index as blockstore is using

async open(): Promise<void> {
await this.db.open();
// TODO: look into using the same level we're using for blockstore
// TODO: parameterize `name`
// calling `searchIndex` twice causes the process to hang, so check to see if the index
// has already been "opened" before opening it again.
if (!this.index) {
this.index = await searchIndex({ name: this.config.indexLocation });
}
}

Consider using my library for key formats

Here is a library that lets you convert between different key formats. Will be helpful when converting between, say, JWK and IPFS key formats, or generating BTC/ETH/IPFS addresses / hashes from secp256k1 keypairs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.