Skip to content

Commit

Permalink
Update tenant-gate.ts (#475)
Browse files Browse the repository at this point in the history
Co-authored-by: Diane Huxley <[email protected]>
Co-authored-by: Henry Tsai <[email protected]>
  • Loading branch information
3 people authored Aug 17, 2023
1 parent b2927e6 commit d793c8a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,26 @@ const result = await window.web5.dwn.processMessage({
});
```
### Custom Tenant Gating
By default, all DIDs are allowed as tenants. A custom tenant gate implementation can be provided when initializing the DWN.
```ts
import { Dwn, TenantGate } from '@tbd54566975/dwn-sdk-js';
import { DataStoreLevel, EventLogLevel, MessageStoreLevel } from '@tbd54566975/dwn-sdk-js/stores';

class CustomTenantGate implements TenantGate {
public async isTenant(did): Promise<void> {
// Custom implementation
// returns `true` if the given DID is a tenant of the DWN; `false` otherwise
}
}

const messageStore = new MessageStoreLevel();
const dataStore = new DataStoreLevel();
const eventLog = new EventLogLevel();
const tenantGate = new CustomTenantGate();
const dwn = await Dwn.create({ messageStore, dataStore, eventLog, tenantGate });
```
## Release/Build Process
The DWN JS SDK releases builds to [npmjs.com](https://www.npmjs.com/package/@tbd54566975/dwn-sdk-js). There are two build types: stable build and unstable build.
Expand Down
2 changes: 1 addition & 1 deletion src/core/tenant-gate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ export class AllowAllTenantGate implements TenantGate {
public async isTenant(_did: string): Promise<boolean> {
return true;
}
}
}

0 comments on commit d793c8a

Please sign in to comment.