diff --git a/BE/issuer/src/issuer/issuer-api.service.ts b/BE/issuer/src/issuer/issuer-api.service.ts index af13b90..03da490 100644 --- a/BE/issuer/src/issuer/issuer-api.service.ts +++ b/BE/issuer/src/issuer/issuer-api.service.ts @@ -88,7 +88,7 @@ export class IssuerAPIService { @ Intend: Issuer Pub Key를 반환 */ getIssuerPubKey() { - return 'meaty-man.testnet'; + return 'honorable-muscle.testnet'; } /* diff --git a/BE/issuer/src/utils/utils.ts b/BE/issuer/src/utils/utils.ts index 75039f9..3612235 100644 --- a/BE/issuer/src/utils/utils.ts +++ b/BE/issuer/src/utils/utils.ts @@ -25,7 +25,7 @@ export async function connectToNEARContract(): Promise { // issuer const account = await nearConnection.account('shaggy-trade.testnet'); - const contract = new Contract(account, 'meaty-man.testnet', { + const contract = new Contract(account, 'honorable-muscle.testnet', { viewMethods: [ 'get_document', 'get_did_list', diff --git a/BE/issuer/test/api.test.spec.ts b/BE/issuer/test/api.test.spec.ts index 1097c25..309f566 100644 --- a/BE/issuer/test/api.test.spec.ts +++ b/BE/issuer/test/api.test.spec.ts @@ -69,6 +69,9 @@ describe('IssuerAPIController (e2e)', () => { expect(res).toHaveProperty('vc'); }); + // TODO + // - issuerPubKey 와 vc{ ... }의 `issuer` 를 통일해야함 + // - `pnu.testnet` 에는 최종 완성된 스마트 컨트랙트를 배포할 예정임 it('Load Key Chain: Success', async () => { const issuerPubKey = 'meaty-man.testnet'; const vc = `{ diff --git a/BE/verifier/src/utils/utils.ts b/BE/verifier/src/utils/utils.ts index 9294627..86bd8db 100644 --- a/BE/verifier/src/utils/utils.ts +++ b/BE/verifier/src/utils/utils.ts @@ -24,7 +24,7 @@ export async function connectToNEARContract(): Promise { const nearConnection = await connect(connectionConfig); const account = await nearConnection.account('shaggy-trade.testnet'); - const contract = new Contract(account, 'meaty-man.testnet', { + const contract = new Contract(account, 'honorable-muscle.testnet', { viewMethods: [ 'get_document', 'get_did_list', diff --git a/SC/readme.md b/SC/readme.md index 8271c4c..424bb38 100644 --- a/SC/readme.md +++ b/SC/readme.md @@ -34,6 +34,17 @@ did:near: - `issuer` 를 등록합니다. - `service`를 등록합니다. +### 예시 +```bash +export CTRT="hello-world.testnet" +near call $CTRT reg_did_using_account --useAccount $CTRT '{"is_issuer": true}' --deposit 5 +near call $CTRT reg_service_name '{"service_name": "kataomoi-boat"}' --useAccount $CTRT +near view $CTRT get_total_registered_services +# [ 'kataomoi-boat' ] +near call $CTRT load_verify_result '{"service_name":"kataomoi-boat", "holder_did": "hpubkey"}' --useAccount $CTRT +near view $CTRT get_servicename_values '{"service_name":"kataomoi-boat"}' +``` + ## 구성 - Smart contract 는 아래와 같이 총 6개의 state를 저장하고 있습니다. diff --git a/SC/src/lib.rs b/SC/src/lib.rs index 13a772a..ecf3adb 100644 --- a/SC/src/lib.rs +++ b/SC/src/lib.rs @@ -28,7 +28,7 @@ struct DidContract { // Set: Issuer DID pub set_issuer_did: UnorderedSet, - // Set: Issuer DID + // Set: Service Name pub set_service_name: UnorderedSet, // Mapping: Issuer DID --> Vec diff --git a/SC/src/utils.rs b/SC/src/utils.rs index 8e946f6..c4be692 100644 --- a/SC/src/utils.rs +++ b/SC/src/utils.rs @@ -3,6 +3,7 @@ use crate::DidContractExt; use crate::DidDocument; use crate::HolderDID; use crate::IssuerDID; +use crate::ServiceName; use crate::DID; use near_sdk::AccountId; @@ -32,6 +33,11 @@ impl DidContract { self.map_holder_did_to_issuer_did.get(&holder_did).unwrap() } + // for service + pub fn get_total_registered_services(&self) -> Vec { + self.set_service_name.iter().collect() + } + pub fn get_mapped_holder_did_validity( &self, holder_did: HolderDID, diff --git a/SC/src/zkp_verify.rs b/SC/src/zkp_verify.rs index 0b07855..9f93c96 100644 --- a/SC/src/zkp_verify.rs +++ b/SC/src/zkp_verify.rs @@ -11,11 +11,18 @@ impl DidContract { service_name: String, holder_did: HolderDID, ) { + if self.set_service_name.contains(&service_name) == false { + env::panic_str( + "Not a registered service, should be registered first", + ); + } + match self.map_servicename_to_holder_validity.get(&service_name) { // 이전에 등록된 Service 인 경우 Some(mut l) => match l.contains(&holder_did) { true => { // 이미 인증된 사용자 + env::panic_str("Already registered user") } false => { // 새로 인증한 사용자 @@ -23,10 +30,13 @@ impl DidContract { } }, None => { - // 등록되지 않은 서비스 - env::panic_str( - "Not a registered service, should be registered first", - ); + // 처음으로 사용자를 등록하는 서비스 + let mut new_hash_set = HashSet::new(); + + new_hash_set.insert(holder_did); + + self.map_servicename_to_holder_validity + .insert(&service_name, &new_hash_set); } }; } @@ -43,4 +53,17 @@ impl DidContract { list_of_valid_holders.contains(&holder_did) } + + // check + pub fn get_servicename_values(&self, service_name: String) -> Vec { + let list_of_valid_holders = self + .map_servicename_to_holder_validity + .get(&service_name) + .expect("No holders had been registered"); + + list_of_valid_holders + .iter() + .map(|v| v.to_string()) + .collect() + } }