Skip to content

Commit

Permalink
Merge branch 'dev' into logger-issuer
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee-clipse committed May 1, 2024
2 parents 0140e9a + 2855caf commit bceab8c
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 8 deletions.
2 changes: 1 addition & 1 deletion BE/issuer/src/issuer/issuer-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class IssuerAPIService {
@ Intend: Issuer Pub Key를 반환
*/
getIssuerPubKey() {
return 'meaty-man.testnet';
return 'honorable-muscle.testnet';
}

/*
Expand Down
2 changes: 1 addition & 1 deletion BE/issuer/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function connectToNEARContract(): Promise<Contract> {
// 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',
Expand Down
3 changes: 3 additions & 0 deletions BE/issuer/test/api.test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `{
Expand Down
2 changes: 1 addition & 1 deletion BE/verifier/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function connectToNEARContract(): Promise<Contract> {
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',
Expand Down
11 changes: 11 additions & 0 deletions SC/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ did:near:<named_account>
- `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를 저장하고 있습니다.

Expand Down
2 changes: 1 addition & 1 deletion SC/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct DidContract {
// Set: Issuer DID
pub set_issuer_did: UnorderedSet<IssuerDID>,

// Set: Issuer DID
// Set: Service Name
pub set_service_name: UnorderedSet<ServiceName>,

// Mapping: Issuer DID --> Vec<HashedVc>
Expand Down
6 changes: 6 additions & 0 deletions SC/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ServiceName> {
self.set_service_name.iter().collect()
}

pub fn get_mapped_holder_did_validity(
&self,
holder_did: HolderDID,
Expand Down
31 changes: 27 additions & 4 deletions SC/src/zkp_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,32 @@ 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 => {
// 새로 인증한 사용자
l.insert(holder_did);
}
},
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);
}
};
}
Expand All @@ -43,4 +53,17 @@ impl DidContract {

list_of_valid_holders.contains(&holder_did)
}

// check
pub fn get_servicename_values(&self, service_name: String) -> Vec<String> {
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()
}
}

0 comments on commit bceab8c

Please sign in to comment.