Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion middleware/thread.config
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"threadId":[1,85,29,234,10,53,7,157,97,192,61,180,56,48,2,22,47,84,9,196,26,127,17,14,50,178,218,79,196,82,4,198,107,129]}
{"threadId":[1,85,187,90,47,202,196,33,70,132,16,200,55,153,171,34,20,16,177,239,202,241,34,186,30,239,14,95,27,14,223,55,109,84]}
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@safient/core",
"version": "0.1.21-alpha.4",
"version": "0.1.21-alpha.5",
"description": "JavaScript SDK to manage safes and interact with Safient protocol.",
"keywords": [
"Web3",
Expand Down Expand Up @@ -37,7 +37,7 @@
"@ceramicstudio/idx": "^0.12.0",
"@ceramicstudio/idx-tools": "^0.10.0",
"@ethersproject/providers": "^5.4.4",
"@safient/contracts": "^0.1.18-alpha",
"@safient/contracts": "^0.1.19-alpha",
"@stablelib/random": "^1.0.1",
"@textile/hub": "^6.3.1",
"bcryptjs": "^2.4.3",
Expand Down
87 changes: 41 additions & 46 deletions src/SafientCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,20 @@ export class SafientCore {
guardian,
};

this.userData = data;

const result: UserResponse = await createUser(
data,
this.connection.idx?.id!
);
if (result.status === false) {
const ceramicResult = await idx?.set(
this.ceramicDefintions.definitions.profile,
{
name: details?.name,
email: details?.email,
}
);
// const ceramicResult = await idx?.set(
// this.ceramicDefintions.definitions.profile,
// {
// name: details?.name,
// email: details?.email,
// }
// );
return new SafientResponse({ data: result.data! });
} else {
throw new SafientResponse({ error: Errors.UserAlreadyExists });
Expand Down Expand Up @@ -342,8 +344,6 @@ export class SafientCore {
const guardiansDid: string[] = [];
//userQueryDid function
// const creatorUser: User[] = await queryUserDid(creatorDID);
const signalPeriod = claimDetails? (claimDetails.type == 0 ? claimDetails.period : 0) : 0;
const dDay = claimDetails? (claimDetails.type == 2 ? claimDetails.period : 0) : 0;
const isBeneficiary = typeof beneficiary == 'object' && beneficiary ? Object.keys(beneficiary).length : false

if (isBeneficiary && beneficiary) {
Expand Down Expand Up @@ -393,9 +393,7 @@ export class SafientCore {
encSafeData: encryptedSafeData.encryptedData,
encSafeKeyShards: encryptedSafeData.shardData,
onChain: onChain,
claimType: claimDetails ? claimDetails?.type : null,
signalingPeriod: signalPeriod,
dDay: dDay,
claim: {type: claimDetails ? claimDetails?.type : null, period: claimDetails?.period ? claimDetails.period : 0},
timeStamp: Date.now(),
};

Expand All @@ -409,16 +407,14 @@ export class SafientCore {
guardians: guardiansDid,
beneficiary: beneficiaryUser? beneficiaryUser?.did : null,
encSafeKey: encryptedSafeData.creatorEncKey,
beneficiaryEncSafeKey: claimDetails ? null : encryptedSafeData.beneficiaryEncKey,
beneficiaryEncSafeKey: claimDetails ? (claimDetails.type !== Types.ClaimType.Expirion ? null : encryptedSafeData.beneficiaryEncKey) : encryptedSafeData.beneficiaryEncKey,
encSafeData: encryptedSafeData.encryptedData,
stage: SafeStages.ACTIVE,
encSafeKeyShards: encryptedSafeData.shardData,
decSafeKeyShards: [],
claims: [],
onChain: onChain,
claimType: claimDetails ? claimDetails?.type : null,
signalingPeriod: signalPeriod,
dDay: dDay,
claim: {type: claimDetails ? claimDetails?.type : null, period: claimDetails?.period ? claimDetails.period : 0},
timeStamp: Date.now(),
proofSubmission: false,
cid: safeLink,
Expand All @@ -445,8 +441,7 @@ export class SafientCore {
beneficiaryUser.userAddress,
safe[0],
claimDetails?.type,
signalPeriod,
dDay,
claimDetails ? claimDetails.period : 0,
metaDataEvidenceUri,
String(ethers.utils.parseEther(String(totalFee)))
); //NOTE: Change the time from 1 to required period here
Expand Down Expand Up @@ -620,7 +615,7 @@ export class SafientCore {

if (parseFloat(etherBalance) >= 0.1) {
if (safe.onChain === true) {
if (safe.claimType === Types.ClaimType.ArbitrationBased) {
if (safe.claim.type === Types.ClaimType.ArbitrationBased) {
if (safe.stage === SafeStages.ACTIVE) {
// Fix the metadata and IPFS stores
// evidenceUri = await createClaimEvidenceUri(
Expand All @@ -632,19 +627,19 @@ export class SafientCore {
tx = await this.contract.createClaim(safe._id, evidenceUri);
txReceipt = await tx.wait();
}
} else if (safe.claimType === Types.ClaimType.SignalBased) {
} else if (safe.claim.type === Types.ClaimType.SignalBased) {
if (safe.stage === SafeStages.ACTIVE) {
tx = await this.contract.createClaim(safe._id, "");
txReceipt = await tx.wait();
}
} else if (safe.claimType === Types.ClaimType.DDayBased) {
} else if (safe.claim.type === Types.ClaimType.DDayBased) {
tx = await this.contract.createClaim(safe._id, "");
txReceipt = await tx.wait();
}
}

if (safe.onChain === false) {
if (safe.claimType === Types.ClaimType.ArbitrationBased) {
if (safe.claim.type === Types.ClaimType.ArbitrationBased) {
// Fix the metadata and IPFS stores
// const metaDataEvidenceUri: string = await createMetaData(
// "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
Expand All @@ -662,48 +657,45 @@ export class SafientCore {
createSafetx = await this.contract.syncSafe(
creatorUser[0].userAddress,
safeId,
safe.claimType,
safe.signalingPeriod,
safe.dDay,
safe.claim.type,
safe.claim.period,
metaDataEvidenceUri,
totalFee
);
createSafetxReceipt = await createSafetx.wait();
}
} else if (safe.claimType === Types.ClaimType.SignalBased) {
} else if (safe.claim.type === Types.ClaimType.SignalBased) {
if (safe.stage === SafeStages.ACTIVE) {
const totalFee: string = String(
ethers.utils.parseEther(String(this.guardianFee))
);
createSafetx = await this.contract.syncSafe(
creatorUser[0].userAddress,
safeId,
safe.claimType,
safe.signalingPeriod,
safe.dDay,
safe.claim.type,
safe.claim.period,
"",
totalFee
); //Note update time here
createSafetxReceipt = await createSafetx.wait();
}
} else if (safe.claimType === Types.ClaimType.DDayBased) {
} else if (safe.claim.type === Types.ClaimType.DDayBased) {
const totalFee: string = String(
ethers.utils.parseEther(String(this.guardianFee))
);
createSafetx = await this.contract.syncSafe(
creatorUser[0].userAddress,
safeId,
safe.claimType,
safe.signalingPeriod,
safe.dDay,
safe.claim.type,
safe.claim.period,
"",
totalFee
); //Note update time here
createSafetxReceipt = await createSafetx.wait();
}

if (createSafetxReceipt.status === 1) {
if (safe.claimType === Types.ClaimType.ArbitrationBased) {
if (safe.claim.type === Types.ClaimType.ArbitrationBased) {
// Fix the metadata and IPFS stores
// evidenceUri = await createClaimEvidenceUri(
// file,
Expand All @@ -720,19 +712,19 @@ export class SafientCore {
}

if (txReceipt.status === 1) {
if (safe.claimType === Types.ClaimType.ArbitrationBased) {
if (safe.claim.type === Types.ClaimType.ArbitrationBased) {
if (safe.stage === SafeStages.ACTIVE) {
dispute = txReceipt.events[2].args[1];
timeStamp = parseInt(txReceipt.events[2].args[2]._hex);
disputeId = parseInt(dispute._hex);
}
} else if (safe.claimType === Types.ClaimType.SignalBased) {
} else if (safe.claim.type === Types.ClaimType.SignalBased) {
if (safe.stage === SafeStages.ACTIVE) {
dispute = txReceipt.events[0].args[1];
timeStamp = parseInt(txReceipt.events[0].args[2]._hex);
disputeId = parseInt(dispute._hex);
}
} else if (safe.claimType === Types.ClaimType.DDayBased) {
} else if (safe.claim.type === Types.ClaimType.DDayBased) {
dispute = txReceipt.events[0].args[1];
timeStamp = parseInt(txReceipt.events[0].args[2]._hex);
disputeId = parseInt(dispute._hex);
Expand Down Expand Up @@ -893,36 +885,39 @@ export class SafientCore {
const safeResponse: SafientResponse<Safe> = await this.getSafe(safeId);
const safe = safeResponse.data!;

// TODO: expiration check is temporary until the recovery happens through claim flow
if (
safe.stage !== SafeStages.RECOVERED &&
safe.stage !== SafeStages.CLAIMED &&
safe.claimType !== null
safe.claim.type !== null &&
safe.claim.type !== Types.ClaimType.Expirion
) {

throw new SafientResponse({ error: Errors.StageNotUpdated });
}

if(safe.claimType !== null) {

if(safe.claim.type == null || safe.claim.type === Types.ClaimType.Expirion) {

beneficiaryEncKey = safe.beneficiaryEncSafeKey;

}
else {
const decShards: DecShard[] = safe.decSafeKeyShards;
decShards.map((shard) => {
shards.push(shard.share);
});

reconstructedSafeData = await this.crypto.reconstructSafeData(shards);
beneficiaryEncKey = reconstructedSafeData.beneficiaryEncKey

}
else {

beneficiaryEncKey = safe.beneficiaryEncSafeKey;
}
safeData = await this.crypto.decryptSafeData(
beneficiaryEncKey,
this.connection,
Buffer.from(safe.encSafeData)
);


if (!safe.claimType) {
if (!safe.claim.type || safe.claim.type == Types.ClaimType.Expirion) {
result = JSON.parse(safeData.toString());
return new SafientResponse({ data: result.data });
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ export const ClaimStages = {
export enum ClaimType {
SignalBased = 0,
ArbitrationBased = 1,
DDayBased = 2
DDayBased = 2,
ExpirationBased = 3
}
8 changes: 2 additions & 6 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ export interface Safe {
decSafeKeyShards: DecShard[];
claims: Claim[];
onChain: boolean;
claimType: Types.ClaimType | null;
signalingPeriod: number,
dDay: number,
claim: { type: Types.ClaimType | null, period: number };
timeStamp: number,
proofSubmission: boolean,
cid: string | null
Expand Down Expand Up @@ -199,9 +197,7 @@ export type SafeLink = {
encSafeData: Buffer;
encSafeKeyShards: Shard[];
onChain: boolean;
claimType: Types.ClaimType | null;
signalingPeriod: number,
dDay: number,
claim: { type: Types.ClaimType | null, period: number };
timeStamp: number
}
export type DecShard = {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const Networks = [
"safientMain": "0x8C2FA3dE952f5A1c463af0Fb42a9A812D3Ffe9e3",
"arbitrator": "0x823E2b7623aD287819674548f43F8965F38B2626"
},
"threadId": [1,85,9,109,19,103,1,168,185,231,88,22,247,217,104,122,75,238,32,212,163,63,22,250,183,121,17,21,244,123,136,157,194,213],
"threadId": [1,85,187,90,47,202,196,33,70,132,16,200,55,153,171,34,20,16,177,239,202,241,34,186,30,239,14,95,27,14,223,55,109,84],
"ceramic": {
"CERAMIC_URL": "https://ceramic-clay.safient.io",
"config": {
Expand Down
6 changes: 4 additions & 2 deletions test/scenario4.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Scenario 4 - Creating signal based Safe', async () => {
const ClaimType = {
SignalBased: 0,
ArbitrationBased: 1,
DDayBased: 2,
DDayBased: 2
};

before(async () => {
Expand Down Expand Up @@ -161,7 +161,8 @@ it('Should register a Guardian 3', async () => {
{did:beneficiary.data.did},
{type: ClaimType.SignalBased, period: 6},
{ name: "On Chain Wallet - signal based",
description: "Hardware wallet instructions"}
description: "Hardware wallet instructions"},
true
);
safeId = safeid.data.id;
const safe = await safient.getSafe(safeId);
Expand Down Expand Up @@ -222,6 +223,7 @@ it('Should register a Guardian 3', async () => {

await safient.loginUser(beneficiarySigner);
const data = await safient.recoverSafeByBeneficiary(safeId, beneficiary.data.did);
console.log(data)
expect(data.data.data.data.hardwareWallet).to.equal('Instruction for hardware wallet');
});

Expand Down
3 changes: 2 additions & 1 deletion test/scenario5.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ describe('Scenario 5 - Creating signal based Safe', async () => {
{did:beneficiary.data.did},
{type: ClaimType.SignalBased, period: 10},
{ name: "Signal based",
description: "generic safe i.e Signal based"}
description: "generic safe i.e Signal based"},
true,
);


Expand Down
Loading