|
|
|
export const SCHEMA_ORG_CONTEXT = "https://schema.org";
|
|
|
|
export const SERVICE_ID = "endorser.ch";
|
|
|
|
|
|
|
|
export interface GenericClaim {
|
|
|
|
"@context": string;
|
|
|
|
"@type": string;
|
|
|
|
issuedAt: string;
|
|
|
|
// "any" because arbitrary objects can be subject of agreement
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
claim: Record<any, any>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface AgreeVerifiableCredential {
|
|
|
|
"@context": string;
|
|
|
|
"@type": string;
|
|
|
|
// "any" because arbitrary objects can be subject of agreement
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
object: Record<any, any>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface GiveServerRecord {
|
|
|
|
agentDid: string;
|
|
|
|
amount: number;
|
|
|
|
amountConfirmed: number;
|
|
|
|
description: string;
|
|
|
|
fullClaim: GiveVerifiableCredential;
|
|
|
|
handleId: string;
|
|
|
|
issuedAt: string;
|
|
|
|
recipientDid: string;
|
|
|
|
unit: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface GiveVerifiableCredential {
|
|
|
|
"@context"?: string; // optional when embedded, eg. in an Agree
|
|
|
|
"@type": string;
|
|
|
|
agent: { identifier: string };
|
|
|
|
description?: string;
|
|
|
|
identifier?: string;
|
|
|
|
object: { amountOfThisGood: number; unitCode: string };
|
|
|
|
recipient: { identifier: string };
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RegisterVerifiableCredential {
|
|
|
|
"@context": string;
|
|
|
|
"@type": string;
|
|
|
|
agent: { identifier: string };
|
|
|
|
object: string;
|
|
|
|
recipient: { identifier: string };
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is used to check for hidden info.
|
|
|
|
// See https://github.com/trentlarson/endorser-ch/blob/0cb626f803028e7d9c67f095858a9fc8542e3dbd/server/api/services/util.js#L6
|
|
|
|
const HIDDEN_DID = "did:none:HIDDEN";
|
|
|
|
|
|
|
|
const UNKNOWN_ENTITY = "Someone Unknown";
|
|
|
|
const UNKNOWN_VISIBLE = "Someone Unnamed";
|
|
|
|
|
|
|
|
export function isHiddenDid(did) {
|
|
|
|
return did === HIDDEN_DID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
always returns text, maybe UNNAMED_VISIBLE or UNKNOWN_ENTITY
|
|
|
|
**/
|
|
|
|
export function didInfo(did, identifiers, contacts) {
|
|
|
|
const myId = R.find((i) => i.did === did, identifiers);
|
|
|
|
if (myId) {
|
|
|
|
return "You";
|
|
|
|
} else {
|
|
|
|
const contact = R.find((c) => c.did === did, contacts);
|
|
|
|
if (contact) {
|
|
|
|
return contact.name || "(no name)";
|
|
|
|
} else if (isHiddenDid(did)) {
|
|
|
|
return UNKNOWN_ENTITY;
|
|
|
|
} else {
|
|
|
|
return UNKNOWN_VISIBLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|