1- import type { AuthCreateOptions } from '../../../core/types' ;
21import type { SignatureInput } from '../../../jose/jws/general/types' ;
32import type { PermissionConditions , PermissionScope } from '../types' ;
43import type { PermissionsGrantDescriptor , PermissionsGrantMessage } from '../types' ;
54
65import { CID } from 'multiformats/cid' ;
7- import { generateCid } from '../../../utils/cid' ;
6+ import { computeCid } from '../../../utils/cid' ;
87import { getCurrentTimeInHighPrecision } from '../../../utils/time' ;
98import { v4 as uuidv4 } from 'uuid' ;
109
1110import { DEFAULT_CONDITIONS , PermissionsRequest } from './permissions-request' ;
1211import { DwnInterfaceName , DwnMethodName , Message } from '../../../core/message' ;
1312
14- type PermissionsGrantOptions = AuthCreateOptions & {
13+ type PermissionsGrantOptions = {
1514 dateCreated ?: string ;
1615 conditions ?: PermissionConditions ;
1716 description : string ;
@@ -20,6 +19,7 @@ type PermissionsGrantOptions = AuthCreateOptions & {
2019 objectId ?: string ;
2120 permissionsRequestId ?: string ;
2221 scope : PermissionScope ;
22+ authorizationSignatureInput : SignatureInput ;
2323} ;
2424
2525export class PermissionsGrant extends Message {
@@ -46,7 +46,7 @@ export class PermissionsGrant extends Message {
4646 scope : options . scope ,
4747 } ;
4848
49- const authorization = await Message . signAsAuthorization ( descriptor , options . signatureInput ) ;
49+ const authorization = await Message . signAsAuthorization ( descriptor , options . authorizationSignatureInput ) ;
5050 const message : PermissionsGrantMessage = { descriptor, authorization } ;
5151
5252 Message . validateJsonSchema ( message ) ;
@@ -58,12 +58,12 @@ export class PermissionsGrant extends Message {
5858 /**
5959 * generates a PermissionsGrant using the provided PermissionsRequest
6060 * @param permissionsRequest
61- * @param signatureInput - the private key and additional signature material of the grantor
61+ * @param authorizationSignatureInput - the private key and additional signature material of the grantor
6262 * @param conditionOverrides - any conditions that the grantor may want to override
6363 */
6464 static async fromPermissionsRequest (
6565 permissionsRequest : PermissionsRequest ,
66- signatureInput : SignatureInput ,
66+ authorizationSignatureInput : SignatureInput ,
6767 conditionOverrides : Partial < PermissionConditions > = { }
6868 ) : Promise < PermissionsGrant > {
6969 const conditions = { ...permissionsRequest . conditions , ...conditionOverrides } ;
@@ -75,33 +75,33 @@ export class PermissionsGrant extends Message {
7575 grantedTo : permissionsRequest . grantedTo ,
7676 permissionsRequestId : permissionsRequest . id ,
7777 scope : permissionsRequest . scope ,
78- signatureInput : signatureInput
78+ authorizationSignatureInput
7979 } ) ;
8080 }
8181
8282 /**
8383 * delegates the permission to the DID provided
8484 * @param to - the DID of the grantee
85- * @param signatureInput - the private key and additional signature material of this permission's `grantedTo`
85+ * @param authorizationSignatureInput - the private key and additional signature material of this permission's `grantedTo`
8686 * @throws {Error } - if the permission cannot be delegated
8787 */
88- async delegate ( to : string , signatureInput : SignatureInput ) : Promise < PermissionsGrant > {
88+ async delegate ( to : string , authorizationSignatureInput : SignatureInput ) : Promise < PermissionsGrant > {
8989 // throw an exception if the permission cannot be delegated
9090 if ( ! this . conditions . delegation ) {
9191 throw new Error ( 'this permission cannot be delegated' ) ;
9292 }
9393
9494 // `grantedBy` of the delegated permission will be `grantedTo` of the permission being delegated because the grantee is the delegator
9595 const delegatedGrant = await PermissionsGrant . create ( {
96- conditions : this . conditions ,
97- description : this . description ,
98- grantedBy : this . grantedTo ,
99- grantedTo : to ,
100- scope : this . scope ,
101- signatureInput : signatureInput
96+ conditions : this . conditions ,
97+ description : this . description ,
98+ grantedBy : this . grantedTo ,
99+ grantedTo : to ,
100+ scope : this . scope ,
101+ authorizationSignatureInput
102102 } ) ;
103103
104- delegatedGrant . delegatedFrom = await generateCid ( this . message ) ;
104+ delegatedGrant . delegatedFrom = await computeCid ( this . message ) ;
105105 delegatedGrant . delegationChain = this . message ;
106106
107107 return delegatedGrant ;
0 commit comments