@@ -12,18 +12,25 @@ export interface CreatePolicyGrantInput {
1212 revocationEndpoint ?: string ;
1313 allowedPurposes ?: string [ ] ;
1414 anchorRef ?: string ;
15- /** Total authorized spend in minor units (e.g. drops for XRP). Signed by the PA. */
1615 budgetMinor ?: string ;
17- /** Currency code for budgetMinor (e.g. "XRP"). Required when budgetMinor is set. */
1816 budgetCurrency ?: string ;
19- /** On-chain escrow locking budgetMinor. Format: "xrpl:escrow:{account}:{sequence}". Signed by the PA. */
2017 budgetEscrowRef ?: string ;
21- /** Address of the only gateway authorized to spend against this grant's escrow. Rail-specific format. PA-signed. */
2218 authorizedGateway ?: string ;
23- /** PA-signed per-transaction cap for offline merchant acceptance, in minor units (see offlineMaxSinglePaymentCurrency). */
2419 offlineMaxSinglePayment ?: string ;
25- /** Currency code for offlineMaxSinglePayment (e.g. "XRP"). */
2620 offlineMaxSinglePaymentCurrency ?: string ;
21+ offlineMaxCumulativePayment ?: string ;
22+ offlineMaxCumulativePaymentCurrency ?: string ;
23+ velocityLimit ?: { maxPayments : number ; windowSeconds : number } ;
24+ maxSpend ?: { perTxMinor ?: string ; perSessionMinor ?: string ; perDayMinor ?: string } ;
25+ destinationAllowlist ?: string [ ] ;
26+ merchantCredentialIssuer ?: string ;
27+ merchantCredentialType ?: string ;
28+ activeGrantCredentialIssuer ?: string ;
29+ gatewayCredentialIssuer ?: string ;
30+ gatewayCredentialType ?: string ;
31+ subjectCredentialIssuer ?: string ;
32+ subjectCredentialType ?: string ;
33+ operatorId ?: string ;
2734}
2835
2936/**
@@ -33,20 +40,30 @@ export interface CreatePolicyGrantInput {
3340 * @returns Policy grant compatible with verifyPolicyGrant / verifySettlement
3441 */
3542export function createPolicyGrant ( input : CreatePolicyGrantInput ) : PolicyGrantLike {
36- return {
43+ const grant : PolicyGrantLike = {
3744 grantId : input . grantId ?? randomUUID ( ) ,
3845 policyHash : input . policyHash ,
3946 expiresAt : input . expiresAt ,
4047 allowedRails : input . allowedRails ,
4148 allowedAssets : input . allowedAssets ?? [ ] ,
42- ...( input . revocationEndpoint ? { revocationEndpoint : input . revocationEndpoint } : { } ) ,
43- ...( input . allowedPurposes ? { allowedPurposes : input . allowedPurposes } : { } ) ,
44- ...( input . anchorRef ? { anchorRef : input . anchorRef } : { } ) ,
45- ...( input . budgetMinor ? { budgetMinor : input . budgetMinor } : { } ) ,
46- ...( input . budgetCurrency ? { budgetCurrency : input . budgetCurrency } : { } ) ,
47- ...( input . budgetEscrowRef ? { budgetEscrowRef : input . budgetEscrowRef } : { } ) ,
48- ...( input . authorizedGateway ? { authorizedGateway : input . authorizedGateway } : { } ) ,
49- ...( input . offlineMaxSinglePayment ? { offlineMaxSinglePayment : input . offlineMaxSinglePayment } : { } ) ,
50- ...( input . offlineMaxSinglePaymentCurrency ? { offlineMaxSinglePaymentCurrency : input . offlineMaxSinglePaymentCurrency } : { } ) ,
5149 } ;
50+ const optionalFields : Array < keyof CreatePolicyGrantInput > = [
51+ "revocationEndpoint" , "allowedPurposes" , "anchorRef" ,
52+ "budgetMinor" , "budgetCurrency" , "budgetEscrowRef" , "authorizedGateway" ,
53+ "offlineMaxSinglePayment" , "offlineMaxSinglePaymentCurrency" ,
54+ "offlineMaxCumulativePayment" , "offlineMaxCumulativePaymentCurrency" ,
55+ "velocityLimit" , "maxSpend" , "destinationAllowlist" ,
56+ "merchantCredentialIssuer" , "merchantCredentialType" ,
57+ "activeGrantCredentialIssuer" ,
58+ "gatewayCredentialIssuer" , "gatewayCredentialType" ,
59+ "subjectCredentialIssuer" , "subjectCredentialType" ,
60+ "operatorId" ,
61+ ] ;
62+ for ( const key of optionalFields ) {
63+ const val = input [ key ] ;
64+ if ( val !== undefined && val !== null ) {
65+ ( grant as Record < string , unknown > ) [ key ] = val ;
66+ }
67+ }
68+ return grant ;
5269}
0 commit comments