-
Notifications
You must be signed in to change notification settings - Fork 57
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
Expose DWN PermissionsGrant Message #252
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import type { PortableDid } from '@web5/dids'; | ||
import type { ManagedIdentity } from '@web5/agent'; | ||
import { Temporal } from '@js-temporal/polyfill'; | ||
|
||
import { expect } from 'chai'; | ||
import { TestManagedAgent } from '@web5/agent'; | ||
|
@@ -8,6 +9,7 @@ import { DwnApi } from '../src/dwn-api.js'; | |
import { testDwnUrl } from './test-config.js'; | ||
import { TestUserAgent } from './utils/test-user-agent.js'; | ||
import emailProtocolDefinition from './fixtures/protocol-definitions/email.json' assert { type: 'json' }; | ||
import { DwnInterfaceName, DwnMethodName } from '@tbd54566975/dwn-sdk-js'; | ||
|
||
let testDwnUrls: string[] = [testDwnUrl]; | ||
|
||
|
@@ -569,4 +571,57 @@ describe('DwnApi', () => { | |
}); | ||
}); | ||
}); | ||
|
||
describe('permissions.grant()', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could a test for sending a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand agents correctly, setting |
||
describe('agent', () => { | ||
it('returns a PermissionsGrant that can be invoked', async () => { | ||
const { did: bobDid } = await testAgent.createIdentity({ testDwnUrls }); | ||
|
||
const { status, permissionsGrant, permissionsGrantId } = await dwn.permissions.grant({ | ||
message: { | ||
dateExpires : Temporal.Now.instant().toString({ smallestUnit: 'microseconds' }), | ||
grantedBy : aliceDid.did, | ||
grantedFor : aliceDid.did, | ||
grantedTo : bobDid.did, | ||
scope : { | ||
interface : DwnInterfaceName.Records, | ||
method : DwnMethodName.Write, | ||
} | ||
}, | ||
}); | ||
|
||
expect(status.code).to.eq(202); | ||
expect(permissionsGrant).not.to.be.undefined; | ||
expect(permissionsGrantId).not.to.be.undefined; | ||
|
||
// send to Alice's remote DWN | ||
const { status: statusSend } = await dwn.permissions.send(aliceDid.did, permissionsGrant); | ||
|
||
expect(statusSend.code).to.eq(202); | ||
}); | ||
}); | ||
|
||
describe('target: did', async () => { | ||
it('returns a PermissionsGrant that can be invoked', async () => { | ||
const { did: bobDid } = await testAgent.createIdentity({ testDwnUrls }); | ||
|
||
const { status, permissionsGrant } = await dwn.permissions.grant({ | ||
target : bobDid.did, | ||
message : { | ||
dateExpires : Temporal.Now.instant().toString({ smallestUnit: 'microseconds' }), | ||
grantedBy : aliceDid.did, | ||
grantedFor : aliceDid.did, | ||
grantedTo : bobDid.did, | ||
scope : { | ||
interface : DwnInterfaceName.Records, | ||
method : DwnMethodName.Write, | ||
} | ||
}, | ||
}); | ||
|
||
expect(status.code).to.eq(202); | ||
expect(permissionsGrant).not.to.be.undefined; | ||
}); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@diehuxx The approach to sending a
PermissionsGrant
is different than how both Record and ProtocolsConfigure messages are sent to a remote DWN. What was the motivation for introducing a new message property to the send request object?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been wanting to make that addition separate of
PermissionsGrants
. The existing code forces an existing message to be turned intooptions
then re built and signed. Why not just send the existing message?