-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
111 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as API from '@ucanto/interface' | ||
|
||
/** | ||
* @template {API.ParsedCapability} C | ||
* @implements {API.Authorization<C>} | ||
*/ | ||
class Authorization { | ||
/** | ||
* @param {API.Match<C>} match | ||
* @param {API.Authorization<API.ParsedCapability>[]} proofs | ||
*/ | ||
constructor(match, proofs) { | ||
this.match = match | ||
this.proofs = proofs | ||
} | ||
get capability() { | ||
return this.match.value | ||
} | ||
get delegation() { | ||
return this.match.source[0].delegation | ||
} | ||
get issuer() { | ||
return this.delegation.issuer | ||
} | ||
get audience() { | ||
return this.delegation.audience | ||
} | ||
} | ||
|
||
/** | ||
* @template {API.ParsedCapability} C | ||
* @param {API.Match<C>} match | ||
* @param {API.Authorization<API.ParsedCapability>[]} proofs | ||
* @returns {API.Authorization<C>} | ||
*/ | ||
export const create = (match, proofs = []) => new Authorization(match, proofs) | ||
|
||
/** | ||
* | ||
* @param {API.Authorization} authorization | ||
* @returns {Iterable<API.UCANLink>} | ||
*/ | ||
export const iterate = function* ({ delegation, proofs }) { | ||
yield delegation.cid | ||
for (const proof of proofs) { | ||
yield* iterate(proof) | ||
} | ||
} |
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