Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnonni committed Aug 29, 2024
2 parents aa21a26 + 9f08161 commit d7252ff
Show file tree
Hide file tree
Showing 59 changed files with 1,381 additions and 335 deletions.
8 changes: 0 additions & 8 deletions .changeset/blue-roses-cough.md

This file was deleted.

12 changes: 0 additions & 12 deletions .changeset/friendly-carrots-return.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/gold-tools-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@web5/api": patch
---

Upgrade `agent` to refelcy the newest `dwn-sdk-js` and `dwn-server`
8 changes: 0 additions & 8 deletions .changeset/polite-days-wash.md

This file was deleted.

8 changes: 0 additions & 8 deletions .changeset/silly-poets-sing.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/spicy-forks-attack.md

This file was deleted.

17 changes: 12 additions & 5 deletions .github/workflows/alpha-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ jobs:

env:
# Packages not listed here will be excluded from publishing
PACKAGES: "agent api common credentials crypto crypto-aws-kms dids identity-agent proxy-agent user-agent"
# These are currently in a specific order due to dependency requirements
PACKAGES: "crypto crypto-aws-kms common dids credentials agent identity-agent proxy-agent user-agent api"

steps:
- name: Checkout source
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #v4.1.1

# https://cashapp.github.io/hermit/usage/ci/
- name: Init Hermit
uses: cashapp/activate-hermit@31ce88b17a84941bb1b782f1b7b317856addf286 #v1.1.0
uses: cashapp/activate-hermit@v1
with:
cache: "true"

Expand Down Expand Up @@ -63,11 +64,17 @@ jobs:
node ./scripts/bump-workspace.mjs --prerelease=$ALPHA_PRERELEASE
shell: bash

- name: Build all workspace packages
- name: Build all workspace packages sequentially
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
run: pnpm --recursive --stream build

run: |
for package in $PACKAGES; do
cd packages/$package
pnpm build
cd ../..
done
shell: bash

- name: Publish selected @web5/* packages
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
Expand Down
3 changes: 2 additions & 1 deletion audit-ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"mysql2",
"braces",
"GHSA-rv95-896h-c2vc",
"GHSA-952p-6rrq-rcjv"
"GHSA-952p-6rrq-rcjv",
"GHSA-4vvj-4cpr-p986"
]
}
55 changes: 29 additions & 26 deletions examples/wallet-connect.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,42 +121,34 @@ <h1>Success</h1>
$actions: [
{
who: "anyone",
can: ["create", "update"],
can: ["read"],
},
],
},
},
};

const scopes = [
{
interface: "Records",
method: "Write",
protocol: "http://profile-protocol.xyz",
},
{
interface: "Records",
method: "Query",
protocol: "http://profile-protocol.xyz",
const fooProtocol = {
protocol: "http://foo-protocol.xyz",
published: true,
types: {
foo: {
schema: "http://foo-protocol.xyz/schema/foo",
dataFormats: ["application/json"],
},
},
{
interface: "Records",
method: "Read",
protocol: "http://profile-protocol.xyz",
structure: {
foo: {},
},
];
};

try {
const { delegateDid } = await Web5.connect({

const { delegateDid, web5 } = await Web5.connect({
walletConnectOptions: {
walletUri: "web5://connect",
connectServerUrl: "http://localhost:3000/connect",
permissionRequests: [
{
protocolDefinition: profileProtocol,
permissionScopes: scopes,
},
],
permissionRequests: [{ protocolDefinition: profileProtocol }, { protocolDefinition: fooProtocol }],
onWalletUriReady: generateQRCode,
validatePin: async () => {
goToPinScreen();
Expand All @@ -167,7 +159,18 @@ <h1>Success</h1>
},
});

goToEndScreen(delegateDid);
// attempt to write to the foo protocol
const { record, status } = await web5.dwn.records.create({
data: { fooData: 'Some Foo Data' },
message: {
protocol: fooProtocol.protocol,
protocolPath: 'foo',
schema: fooProtocol.types.foo.schema,
dataFormat: fooProtocol.types.foo.dataFormats[0],
}
});

goToEndScreen(delegateDid, record, status);
} catch (e) {
document.getElementById(
"errorMessage"
Expand Down Expand Up @@ -210,12 +213,12 @@ <h1>Success</h1>
document.getElementById("pinScreen").style.display = "block";
}

function goToEndScreen(delegateDid) {
function goToEndScreen(delegateDid, record, status) {
document.getElementById(
"didInformation"
).innerText = `delegateDid\n:${JSON.stringify(
delegateDid
)}`;
)}\n\n\nRecordsWrite Status:${JSON.stringify(status)}\nRecord:${JSON.stringify(record, null, 2)}`;

document.getElementById("pinScreen").style.display = "none";
document.getElementById("endScreen").style.display = "block";
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@changesets/cli": "^2.27.5",
"@npmcli/package-json": "5.0.0",
"@typescript-eslint/eslint-plugin": "7.9.0",
"@web5/dwn-server": "0.4.7",
"@web5/dwn-server": "0.4.8",
"audit-ci": "^7.0.1",
"eslint-plugin-mocha": "10.4.3",
"globals": "^13.24.0",
Expand All @@ -47,7 +47,8 @@
"elliptic@>=4.0.0 <=6.5.6": ">=6.5.7",
"elliptic@>=2.0.0 <=6.5.6": ">=6.5.7",
"elliptic@>=5.2.1 <=6.5.6": ">=6.5.7",
"micromatch@<4.0.8": ">=4.0.8"
"micromatch@<4.0.8": ">=4.0.8",
"webpack@<5.94.0": ">=5.94.0"
}
}
}
32 changes: 32 additions & 0 deletions packages/agent/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
# @web5/agent

## 0.6.1

### Patch Changes

- [#857](https://github.com/TBD54566975/web5-js/pull/857) [`226455a`](https://github.com/TBD54566975/web5-js/commit/226455a7d6029292c810e67d80e129e2e20f83da) Thanks [@LiranCohen](https://github.com/LiranCohen)! - Sync vs StartSync conflicting error.

## 0.6.0

### Minor Changes

- [#836](https://github.com/TBD54566975/web5-js/pull/836) [`3d1f825`](https://github.com/TBD54566975/web5-js/commit/3d1f8258465e1177d6d5fe17c2e1ea786baa331d) Thanks [@LiranCohen](https://github.com/LiranCohen)! - Add ability to Sync a subset of protocols as a delegate

- [#824](https://github.com/TBD54566975/web5-js/pull/824) [`0862ffc`](https://github.com/TBD54566975/web5-js/commit/0862ffc1f23550406ff592e8393cb2eb5a769079) Thanks [@LiranCohen](https://github.com/LiranCohen)! - Simplify support for Permission Grant logic within agent.

### Patch Changes

- [#854](https://github.com/TBD54566975/web5-js/pull/854) [`4ff2316`](https://github.com/TBD54566975/web5-js/commit/4ff2316e28ad3f29f0336c69adde0a37840ebb33) Thanks [@LiranCohen](https://github.com/LiranCohen)! - Add requestPermissionsForProtocol helper method to connect module

- [#838](https://github.com/TBD54566975/web5-js/pull/838) [`2d0b423`](https://github.com/TBD54566975/web5-js/commit/2d0b423b90546c8d28735b600328c8a5937b57c8) Thanks [@shamilovtim](https://github.com/shamilovtim)! - cleanup crypto utils

- [#855](https://github.com/TBD54566975/web5-js/pull/855) [`5ac4fe5`](https://github.com/TBD54566975/web5-js/commit/5ac4fe51a2a87a266e95c3db8215059ac2d38e77) Thanks [@LiranCohen](https://github.com/LiranCohen)! - Implement DidResolverCache thats specific to Agent usage

- [#824](https://github.com/TBD54566975/web5-js/pull/824) [`0862ffc`](https://github.com/TBD54566975/web5-js/commit/0862ffc1f23550406ff592e8393cb2eb5a769079) Thanks [@LiranCohen](https://github.com/LiranCohen)! - Introduce a `PermissionsApi` for Web5Agents

- [#850](https://github.com/TBD54566975/web5-js/pull/850) [`fea0535`](https://github.com/TBD54566975/web5-js/commit/fea0535876d5b00ab5e0abea695e52aeaad9d78b) Thanks [@shamilovtim](https://github.com/shamilovtim)! - integrate dwn grants into connect flow

- [#853](https://github.com/TBD54566975/web5-js/pull/853) [`7347438`](https://github.com/TBD54566975/web5-js/commit/734743884f21491efce9392e129d612735e85282) Thanks [@LiranCohen](https://github.com/LiranCohen)! - Upgrade `dwn-sdk-js` version and `dwn-server` dependency

- Updated dependencies [[`2d0b423`](https://github.com/TBD54566975/web5-js/commit/2d0b423b90546c8d28735b600328c8a5937b57c8), [`5ac4fe5`](https://github.com/TBD54566975/web5-js/commit/5ac4fe51a2a87a266e95c3db8215059ac2d38e77)]:
- @web5/crypto@1.0.4
- @web5/dids@1.1.4

## 0.5.1

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/agent/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web5/agent",
"version": "0.5.1",
"version": "0.6.1",
"type": "module",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
Expand Down Expand Up @@ -71,10 +71,10 @@
"dependencies": {
"@noble/ciphers": "0.5.3",
"@scure/bip39": "1.2.2",
"@tbd54566975/dwn-sdk-js": "0.4.5",
"@tbd54566975/dwn-sdk-js": "0.4.6",
"@web5/common": "1.0.0",
"@web5/crypto": "workspace:*",
"@web5/dids": "1.1.0",
"@web5/dids": "workspace:*",
"abstract-level": "1.0.4",
"ed25519-keygen": "0.4.11",
"isomorphic-ws": "^5.0.0",
Expand Down
72 changes: 72 additions & 0 deletions packages/agent/src/agent-did-resolver-cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { DidResolutionResult, DidResolverCache, DidResolverCacheLevel, DidResolverCacheLevelParams } from '@web5/dids';
import { Web5PlatformAgent } from './types/agent.js';


/**
* AgentDidResolverCache keeps a stale copy of the Agent's managed Identity DIDs and only evicts and refreshes upon a successful resolution.
* This allows for quick and offline access to the internal DIDs used by the agent.
*/
export class AgentDidResolverCache extends DidResolverCacheLevel implements DidResolverCache {

/**
* Holds the instance of a `Web5PlatformAgent` that represents the current execution context for
* the `AgentDidApi`. This agent is used to interact with other Web5 agent components. It's vital
* to ensure this instance is set to correctly contextualize operations within the broader Web5
* Agent framework.
*/
private _agent?: Web5PlatformAgent;

/** A map of DIDs that are currently in-flight. This helps avoid going into an infinite loop */
private _resolving: Map<string, boolean> = new Map();

constructor({ agent, db, location, ttl }: DidResolverCacheLevelParams & { agent?: Web5PlatformAgent }) {
super ({ db, location, ttl });
this._agent = agent;
}

get agent() {
if (!this._agent) {
throw new Error('Agent not initialized');
}
return this._agent;
}

set agent(agent: Web5PlatformAgent) {
this._agent = agent;
}

/**
* Get the DID resolution result from the cache for the given DID.
*
* If the DID is managed by the agent, or is the agent's own DID, it will not evict it from the cache until a new resolution is successful.
* This is done to achieve quick and offline access to the agent's own managed DIDs.
*/
async get(did: string): Promise<DidResolutionResult | void> {
try {
const str = await this.cache.get(did);
const cachedResult = JSON.parse(str);
if (!this._resolving.has(did) && Date.now() >= cachedResult.ttlMillis) {
this._resolving.set(did, true);
if (this.agent.agentDid.uri === did || 'undefined' !== typeof await this.agent.identity.get({ didUri: did })) {
try {
const result = await this.agent.did.resolve(did);
if (!result.didResolutionMetadata.error) {
this.set(did, result);
}
} finally {
this._resolving.delete(did);
}
} else {
this._resolving.delete(did);
this.cache.nextTick(() => this.cache.del(did));
}
}
return cachedResult.value;
} catch(error: any) {
if (error.notFound) {
return;
}
throw error;
}
}
}
Loading

0 comments on commit d7252ff

Please sign in to comment.