Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
feat: revocation types & revocation verification (#32)
Browse files Browse the repository at this point in the history
Signed-off-by: James Ebert <[email protected]>
  • Loading branch information
JamesKEbert authored Feb 1, 2022
1 parent f5453b9 commit 4125e85
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 11 deletions.
31 changes: 31 additions & 0 deletions android/src/main/java/com/reactlibrary/IndySdkModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,37 @@ public void parseGetRevocRegDeltaResponse(String getRevocRegDeltaResponse, Promi
}
}

@ReactMethod
public void buildGetRevocRegRequest(
String submitterDid,
String revocRegDefId,
int timestamp,
Promise promise
){
try{
String request = Ledger.buildGetRevocRegRequest(submitterDid,revocRegDefId,timestamp).get();
promise.resolve(request);
}catch(Exception e) {
IndySdkRejectResponse rejectResponse = new IndySdkRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}

@ReactMethod
public void parseGetRevocRegResponse(String getRevocRegResponse, Promise promise){
try{
LedgerResults.ParseRegistryResponseResult ledgerResult = Ledger.parseGetRevocRegResponse(getRevocRegResponse).get();
WritableArray result = new WritableNativeArray();
result.pushString(ledgerResult.getId());
result.pushString(ledgerResult.getObjectJson());
result.pushInt((int) ledgerResult.getTimestamp());
promise.resolve(result);
}catch(Exception e){
IndySdkRejectResponse rejectResponse = new IndySdkRejectResponse(e);
promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
}
}

@ReactMethod
public void buildGetAttribRequest(String submitterDid, String targetDid, String raw, String hash, String enc, Promise promise) {
try {
Expand Down
8 changes: 8 additions & 0 deletions ios/IndySdk.m
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ @interface RCT_EXTERN_MODULE(IndySdk, NSObject)
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(buildGetRevocRegRequest: (NSString *)submitterDid id:(NSString *)id timestamp:(nonnull NSNumber *)timestamp
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(parseGetRevocRegResponse: (NSString *)getRevocRegResponse
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(buildGetAttribRequest: (nullable NSString *)submitterDid
targetDid:(NSString *)targetDid
raw:(nullable NSString *)raw
Expand Down
19 changes: 19 additions & 0 deletions ios/IndySdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,26 @@ class IndySdk : NSObject {
rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
IndyLedger.parseGetRevocRegDeltaResponse(getRevocRegDeltaResponse, completion: completionWithStringPairAndNumber(resolve, reject))
}


@objc func buildGetRevocRegDeltaRequest(_ submitterDid: String, id: String, timestamp: NSNumber,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
IndyLedger.buildGetRevocRegRequest(
withSubmitterDid: !submitterDid.isEmpty ? submitterDid : nil,
revocRegDefId: id,
timestamp: timestamp,
completion: completionWithString(resolve, reject)
)
}

@objc func parseGetRevocRegResponse(_ getRevocRegResponse: String,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
IndyLedger.parseGetRevocRegResponse(getRevocRegResponse, completion: completionWithStringPairAndNumber(resolve, reject))
}


@objc func buildGetAttribRequest(_ submitterDid: String?,
targetDid: String,
raw: String?,
Expand Down
37 changes: 26 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,6 @@ interface CredValue {
*/
export type CredReqMetadata = {}

/**
* Json - revocation registry definition json related to <rev_reg_def_id> in <cred_json>
*/
export type RevRegDef = {}

export type RevRegId = string
export type CredRevocId = string
export type RevocRegDef = {
Expand All @@ -244,6 +239,9 @@ export type RevocRegDef = {
},
ver: string,
}
export type RevocRegDefs = {
[revRegId: string]: RevocRegDef,
}
export type RevocRegDelta = Record<string, unknown>
export type TailsWriterConfig = {
base_dir: string,
Expand Down Expand Up @@ -527,7 +525,7 @@ const indy = {
return JSON.parse(await IndySdk.buildGetRevocRegDefRequest(submitterDid, revocRegDefId))
},

async parseGetRevocRegDefResponse(getRevocRegResponse: LedgerRequestResult): Promise<[RevRegId, RevRegDef]> {
async parseGetRevocRegDefResponse(getRevocRegResponse: LedgerRequestResult): Promise<[RevRegId, RevocRegDef]> {
const [revocRegDefId, revocRegDef] = await IndySdk.parseGetRevocRegDefResponse(JSON.stringify(getRevocRegResponse))
return [revocRegDefId, JSON.parse(revocRegDef)]
},
Expand All @@ -541,13 +539,30 @@ const indy = {
return JSON.parse(await IndySdk.buildGetRevocRegDeltaRequest(submitterDid, revocRegDefId, from, to))
},

async parseGetRevocRegDeltaResponse(getRevocRegDeltaResponse: string): Promise<[RevRegId, RevocRegDelta, number]> {
async parseGetRevocRegDeltaResponse(
getRevocRegDeltaResponse: LedgerRequestResult
): Promise<[RevRegId, RevocRegDelta, number]> {
const [revocRegId, revocRegDelta, timestamp] = await IndySdk.parseGetRevocRegDeltaResponse(
JSON.stringify(getRevocRegDeltaResponse)
)
return [revocRegId, JSON.parse(revocRegDelta), timestamp]
},

async buildGetRevocRegRequest(
submitterDid: Did | null,
revocRegDefId: string,
timestamp: number
): Promise<LedgerRequest> {
return JSON.parse(await IndySdk.buildGetRevocRegRequest(submitterDid, revocRegDefId, timestamp))
},

async parseGetRevocRegResponse(getRevocRegResponse: LedgerRequestResult): Promise<[RevRegId, RevocReg, number]> {
const [revocRegId, revocReg, ledgerTimestamp] = await IndySdk.parseGetRevocRegResponse(
JSON.stringify(getRevocRegResponse)
)
return [revocRegId, JSON.parse(revocReg), ledgerTimestamp]
},

async proverCreateMasterSecret(wh: WalletHandle, masterSecretId: ?MasterSecretId): Promise<MasterSecretId> {
if (Platform.OS === 'ios') {
return IndySdk.proverCreateMasterSecret(masterSecretId, wh)
Expand Down Expand Up @@ -584,11 +599,11 @@ const indy = {

proverStoreCredential(
wh: WalletHandle,
credId: CredId,
credId: CredId | null,
credReqMetadata: CredReqMetadata,
cred: Cred,
credDef: CredDef,
revRegDef: ?RevRegDef
revRegDef: RevocRegDef | null
): Promise<CredId> {
if (Platform.OS === 'ios') {
return IndySdk.proverStoreCredential(
Expand Down Expand Up @@ -703,15 +718,15 @@ const indy = {
proof: Proof,
schemas: Schemas,
credentialDefs: CredentialDefs,
revRegDef: ?RevRegDef,
revRegDefs: RevocRegDefs,
revStates: RevStates
): Promise<boolean> {
return IndySdk.verifierVerifyProof(
JSON.stringify(proofRequest),
JSON.stringify(proof),
JSON.stringify(schemas),
JSON.stringify(credentialDefs),
revRegDef && JSON.stringify(revRegDef),
JSON.stringify(revRegDefs),
JSON.stringify(revStates)
)
},
Expand Down

0 comments on commit 4125e85

Please sign in to comment.