Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow overriding of DWN hosts #93

Merged
merged 7 commits into from
May 28, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,34 @@ or
import { Web5 } from CDN_LINK_HERE;
```

### **`Web5.connect()`**
### **`Web5.connect(options)`**

Enables an app to request connection to a user's local identity app (like a desktop or mobile agent - work is underway for reference apps of each), or generate an in-app DID to represent the user (e.g. if the user does not have an identity app).

> **NOTE:** The outputs of this method invocation with be used throughout the other API methods below.
> **NOTE:** The outputs of this method invocation will be used throughout the other API methods below.

```javascript
const { web5, did: myDid } = await Web5.connect();
```

#### **`options`** _(optional)_

An object which may specify any of the following properties:

- **`techPreview`** - _`object`_ _(optional)_: an object that specifies configuration parameters that are relevant during the Tech Preview period of Web5 JS and may be deprecated in the future with advance notice.

- **`dwnEndpoints`** - _`array`_ _(optional)_: a list of DWeb Node endpoints to define in the DID created and returned by `Web5.connect()`. If this property is omitted, during the Tech Preview two nodes will be included by default (e.g., `['https://dwn.tbddev.org/dwn0', 'https://dwn.tbddev.org/dwn3']`).

For example:

```typescript
const { web5, did: myDid } = await Web5.connect({
techPreview: {
dwnEndpoints: ["https://dwn.your-domain.org/"],
},
});
```

<!-- > NOTE: This method **_MUST_** be invoked within the scope of a 'trusted user action' (something enforced by the OS/browser) if the desire is to connect to a local identity app. For browsers this is generally some direct user action, like clicking a link or button. -->

#### **Response**
Expand All @@ -79,7 +97,7 @@ Each `Record` instance has the following instance properties: `id`, `attestation

Each `Record` instance has the following instance methods:

- **`data`** - _`object`_: a object with the following convenience methods that read out the data of the record entry in the following formats:
- **`data`** - _`object`_: an object with the following convenience methods that read out the data of the record entry in the following formats:
- **`text`** - _`function`_: produces a textual representation of the data.
- **`json`** - _`function`_: if the value is JSON data, this method will return a parsed JSON object.
- **`stream`** - _`function`_: returns the raw stream of bytes for the data.
Expand Down
7 changes: 4 additions & 3 deletions packages/crypto/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/** @type {import('eslint').ESLint.ConfigData} */
module.exports = {
extends : ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
Expand Down Expand Up @@ -43,7 +42,9 @@ module.exports = {
'varsIgnorePattern' : '^_'
}
],
'@typescript-eslint/no-explicit-any' : 'off',
'no-trailing-spaces' : ['error'],
'@typescript-eslint/no-explicit-any' : 'off',
'no-trailing-spaces' : ['error'],
'@typescript-eslint/no-non-null-assertion' : 'off',
'@typescript-eslint/ban-ts-comment' : 'off'
}
};
7 changes: 4 additions & 3 deletions packages/dids/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/** @type {import('eslint').ESLint.ConfigData} */
module.exports = {
extends : ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
Expand Down Expand Up @@ -43,7 +42,9 @@ module.exports = {
'varsIgnorePattern' : '^_'
}
],
'@typescript-eslint/no-explicit-any' : 'off',
'no-trailing-spaces' : ['error'],
'@typescript-eslint/no-explicit-any' : 'off',
'no-trailing-spaces' : ['error'],
'@typescript-eslint/no-non-null-assertion' : 'off',
'@typescript-eslint/ban-ts-comment' : 'off'
}
};
37 changes: 14 additions & 23 deletions packages/dids/tests/did-ion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,21 @@ import { DidIonApi } from '../src/did-ion.js';
const DidIon = new DidIonApi();

describe('DidIonApi', () => {
it('works', async () => {
const didState = await DidIon.create();
describe('create()', () => {
it('returns a valid didState', async () => {
const didState = await DidIon.create();

expect(didState.id).to.exist;
expect(didState.internalId).to.exist;
expect(didState.keys).to.exist;
expect(didState.id).to.exist;
expect(didState.internalId).to.exist;
expect(didState.keys).to.exist;

for (let key of didState.keys) {
expect(key.id).to.exist;
expect(key.controller).to.exist;
expect(key.publicKeyJwk).to.exist;
expect(key.privateKeyJwk).to.exist;
expect(key.type).to.exist;
}
});

it('works when using dwn configuration', async () => {
const ionCreateOptions = await DidIonApi.generateDwnConfiguration(['https://dwn.tbddev.org/dwn0']);

try {
// TODO: write specific assertions
const _didState = await DidIon.create(ionCreateOptions);
} catch(e) {
expect.fail(e.message);
}
for (let key of didState.keys) {
expect(key.id).to.exist;
expect(key.controller).to.exist;
expect(key.publicKeyJwk).to.exist;
expect(key.privateKeyJwk).to.exist;
expect(key.type).to.exist;
}
});
});
});
68 changes: 68 additions & 0 deletions packages/dids/tests/tech-preview.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type { DwnServiceEndpoint } from '../src/types.js';

import { expect } from 'chai';

import { DidIonApi } from '../src/did-ion.js';

describe('Tech Preview', function () {
describe('generateDwnConfiguration()', () => {
it('returns keys and services with two DWN URLs', async () => {
const ionCreateOptions = await DidIonApi.generateDwnConfiguration([
'https://dwn.tbddev.test/dwn0',
'https://dwn.tbddev.test/dwn1'
]);

expect(ionCreateOptions).to.have.property('keys');
expect(ionCreateOptions.keys).to.have.lengthOf(2);
let encryptionKey = ionCreateOptions.keys!.find(key => key.id === 'enc');
expect(encryptionKey).to.exist;
let authorizationKey = ionCreateOptions.keys!.find(key => key.id === 'authz');
expect(authorizationKey).to.exist;

expect(ionCreateOptions).to.have.property('services');
expect(ionCreateOptions.services).to.have.lengthOf(1);

const [ service ] = ionCreateOptions.services!;
expect(service.id).to.equal('dwn');
expect(service).to.have.property('serviceEndpoint');

const serviceEndpoint = service.serviceEndpoint as DwnServiceEndpoint;
expect(serviceEndpoint).to.have.property('nodes');
expect(serviceEndpoint.nodes).to.have.lengthOf(2);
expect(serviceEndpoint).to.have.property('messageAuthorizationKeys');
expect(serviceEndpoint!.messageAuthorizationKeys![0]).to.equal(`#${authorizationKey!.id}`);
expect(serviceEndpoint).to.have.property('recordEncryptionKeys');
expect(serviceEndpoint!.recordEncryptionKeys![0]).to.equal(`#${encryptionKey!.id}`);
});

it('returns keys and services with one DWN URLs', async () => {
const ionCreateOptions = await DidIonApi.generateDwnConfiguration([
'https://dwn.tbddev.test/dwn0'
]);

const [ service ] = ionCreateOptions.services!;
expect(service.id).to.equal('dwn');
expect(service).to.have.property('serviceEndpoint');

const serviceEndpoint = service.serviceEndpoint as DwnServiceEndpoint;
expect(serviceEndpoint).to.have.property('nodes');
expect(serviceEndpoint.nodes).to.have.lengthOf(1);
expect(serviceEndpoint).to.have.property('messageAuthorizationKeys');
expect(serviceEndpoint).to.have.property('recordEncryptionKeys');
});

it('returns keys and services with 0 DWN URLs', async () => {
const ionCreateOptions = await DidIonApi.generateDwnConfiguration([]);

const [ service ] = ionCreateOptions.services!;
expect(service.id).to.equal('dwn');
expect(service).to.have.property('serviceEndpoint');

const serviceEndpoint = service.serviceEndpoint as DwnServiceEndpoint;
expect(serviceEndpoint).to.have.property('nodes');
expect(serviceEndpoint.nodes).to.have.lengthOf(0);
expect(serviceEndpoint).to.have.property('messageAuthorizationKeys');
expect(serviceEndpoint).to.have.property('recordEncryptionKeys');
});
});
});
7 changes: 4 additions & 3 deletions packages/web5-agent/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/** @type {import('eslint').ESLint.ConfigData} */
module.exports = {
extends : ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
Expand Down Expand Up @@ -43,7 +42,9 @@ module.exports = {
'varsIgnorePattern' : '^_'
}
],
'@typescript-eslint/no-explicit-any' : 'off',
'no-trailing-spaces' : ['error'],
'@typescript-eslint/no-explicit-any' : 'off',
'no-trailing-spaces' : ['error'],
'@typescript-eslint/no-non-null-assertion' : 'off',
'@typescript-eslint/ban-ts-comment' : 'off'
}
};
7 changes: 4 additions & 3 deletions packages/web5-proxy-agent/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/** @type {import('eslint').ESLint.ConfigData} */
module.exports = {
extends : ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
Expand Down Expand Up @@ -43,7 +42,9 @@ module.exports = {
'varsIgnorePattern' : '^_'
}
],
'@typescript-eslint/no-explicit-any' : 'off',
'no-trailing-spaces' : ['error'],
'@typescript-eslint/no-explicit-any' : 'off',
'no-trailing-spaces' : ['error'],
'@typescript-eslint/no-non-null-assertion' : 'off',
'@typescript-eslint/ban-ts-comment' : 'off'
}
};
9 changes: 6 additions & 3 deletions packages/web5-user-agent/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('eslint').ESLint.ConfigData} */
module.exports = {
extends : ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser : '@typescript-eslint/parser',
Expand All @@ -7,8 +8,9 @@ module.exports = {
},
plugins : ['@typescript-eslint'],
env : {
node : true,
es2022 : true
node : true,
es2022 : true,
browser : true
},
rules: {
'key-spacing': [
Expand Down Expand Up @@ -42,6 +44,7 @@ module.exports = {
],
'@typescript-eslint/no-explicit-any' : 'off',
'no-trailing-spaces' : ['error'],
'@typescript-eslint/no-non-null-assertion' : 'off'
'@typescript-eslint/no-non-null-assertion' : 'off',
'@typescript-eslint/ban-ts-comment' : 'off'
}
};
2 changes: 1 addition & 1 deletion packages/web5/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

/** @type {import('eslint').ESLint.ConfigData} */
module.exports = {
extends : ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser : '@typescript-eslint/parser',
Expand Down
24 changes: 21 additions & 3 deletions packages/web5/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,34 @@ or
import { Web5 } from CDN_LINK_HERE;
```

### **`Web5.connect()`**
### **`Web5.connect(options)`**

Enables an app to request connection to a user's local identity app (like a desktop or mobile agent - work is underway for reference apps of each), or generate an in-app DID to represent the user (e.g. if the user does not have an identity app).

> **NOTE:** The outputs of this method invocation with be used throughout the other API methods below.
> **NOTE:** The outputs of this method invocation will be used throughout the other API methods below.

```javascript
const { web5, did: myDid } = await Web5.connect();
```

#### **`options`** _(optional)_

An object which may specify any of the following properties:

- **`techPreview`** - _`object`_ _(optional)_: an object that specifies configuration parameters that are relevant during the Tech Preview period of Web5 JS and may be deprecated in the future with advance notice.

- **`dwnEndpoints`** - _`array`_ _(optional)_: a list of DWeb Node endpoints to define in the DID created and returned by `Web5.connect()`. If this property is omitted, during the Tech Preview two nodes will be included by default (e.g., `['https://dwn.tbddev.org/dwn0', 'https://dwn.tbddev.org/dwn3']`).

For example:

```typescript
const { web5, did: myDid } = await Web5.connect({
techPreview: {
dwnEndpoints: ["https://dwn.your-domain.org/"],
},
});
```

<!-- > NOTE: This method **_MUST_** be invoked within the scope of a 'trusted user action' (something enforced by the OS/browser) if the desire is to connect to a local identity app. For browsers this is generally some direct user action, like clicking a link or button. -->

#### **Response**
Expand All @@ -79,7 +97,7 @@ Each `Record` instance has the following instance properties: `id`, `attestation

Each `Record` instance has the following instance methods:

- **`data`** - _`object`_: a object with the following convenience methods that read out the data of the record entry in the following formats:
- **`data`** - _`object`_: an object with the following convenience methods that read out the data of the record entry in the following formats:
- **`text`** - _`function`_: produces a textual representation of the data.
- **`json`** - _`function`_: if the value is JSON data, this method will return a parsed JSON object.
- **`stream`** - _`function`_: returns the raw stream of bytes for the data.
Expand Down
Loading