-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: access/authorize confirmation email click results in a delegati…
…on back to the issuer did:key so that access/claim works (#460) Motivation: * #455 * This implements the second delegation described in #457 * make this test pass once we deploy this to staging gobengo/w3protocol-test#6 Test Case: * https://github.com/gobengo/w3protocol-test/pull/6/files#diff-698e92d7467a4a470689d4cb120272c6cac28864d4960ac12a3720ab7c35a15cR364 --------- Co-authored-by: Irakli Gozalishvili <[email protected]>
- Loading branch information
Showing
7 changed files
with
223 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { Delegation } from '@ucanto/core' | ||
import { Delegation, invoke } from '@ucanto/core' | ||
import * as Voucher from '@web3-storage/capabilities/voucher' | ||
import { stringToDelegation } from '@web3-storage/access/encoding' | ||
import { context } from './helpers/context.js' | ||
import assert from 'assert' | ||
import * as principal from '@ucanto/principal' | ||
|
||
/** @type {typeof assert} */ | ||
const t = assert | ||
|
@@ -67,3 +68,43 @@ describe('ucan', function () { | |
} | ||
}) | ||
}) | ||
|
||
describe('voucher/claim', () => { | ||
it('invoking delegation from confirmation email should not error', async () => { | ||
const { service, conn } = await context() | ||
const issuer = await principal.ed25519.generate() | ||
const claim = Voucher.claim.invoke({ | ||
issuer, | ||
audience: service, | ||
with: issuer.did(), | ||
nb: { | ||
identity: 'mailto:[email protected]', | ||
product: 'product:free', | ||
service: service.did(), | ||
}, | ||
}) | ||
// @todo should not need to cast to string | ||
// this function only returns a string when ENV==='test' and that's weird | ||
const claimResult = /** @type {string} */ (await claim.execute(conn)) | ||
assert.deepEqual(typeof claimResult, 'string', 'claim result is a string') | ||
const confirmEmailDelegation = await stringToDelegation( | ||
claimResult | ||
).delegate() | ||
const confirmEmailReceipt = await invoke({ | ||
issuer, | ||
audience: service, | ||
capability: confirmEmailDelegation.capabilities[0], | ||
proofs: [confirmEmailDelegation], | ||
}).delegate() | ||
const [confirmEmailReceiptResult] = await conn.execute( | ||
/** @type {any} */ (confirmEmailReceipt) | ||
) | ||
assert.notDeepEqual( | ||
confirmEmailReceiptResult && | ||
'error' in confirmEmailReceiptResult && | ||
confirmEmailReceiptResult.error, | ||
true, | ||
'invocation result is not an error' | ||
) | ||
}) | ||
}) |