Skip to content

Commit

Permalink
Merge pull request #261 from logion-network/feature/mock-secrets
Browse files Browse the repository at this point in the history
Mock access to secrets.
  • Loading branch information
benoitdevos authored May 14, 2024
2 parents c09d0ec + 21f97d6 commit f29e6b8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@logion/client",
"version": "0.45.0-2",
"version": "0.45.0-4",
"description": "logion SDK for client applications",
"main": "dist/index.js",
"packageManager": "[email protected]",
Expand Down
33 changes: 31 additions & 2 deletions packages/client/src/Loc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
PublishFileParams,
PublishMetadataParams,
PublishLinkParams,
Secret,
} from "./LocClient.js";
import { BlockchainSubmission, BlockchainBatchSubmission, BasicBlockchainSubmission } from "./Signer.js";
import { SharedState, getLegalOfficer } from "./SharedClient.js";
Expand Down Expand Up @@ -755,7 +756,7 @@ export type AnyLocState = OffchainLocState | OnchainLocState;

export type OffchainLocState = DraftRequest | PendingRequest | RejectedRequest | AcceptedRequest;

export type OnchainLocState = OpenLoc | ClosedLoc | ClosedCollectionLoc | VoidedLoc | VoidedCollectionLoc;
export type OnchainLocState = OpenLoc | ClosedLoc | ClosedIdentityLoc | ClosedCollectionLoc | VoidedLoc | VoidedCollectionLoc;

export abstract class LocRequestState extends State {

Expand All @@ -765,6 +766,7 @@ export abstract class LocRequestState extends State {
protected readonly locIssuers: LocVerifiedIssuers;
protected readonly invitedContributors: ValidAccountId[];
readonly owner: LegalOfficerClass;
protected _secrets: Record<string, Secret> = {}; // TODO for stubbing only, move secrets to LocRequest.

constructor(locSharedState: LocSharedState, request: LocRequest, legalOfficerCase: LegalOfficerCase | undefined, locIssuers: LocVerifiedIssuers, invitedContributors: ValidAccountId[]) {
super();
Expand All @@ -774,7 +776,8 @@ export abstract class LocRequestState extends State {
this.locIssuers = locIssuers;
this.invitedContributors = invitedContributors;

const owner = locSharedState.allLegalOfficers.find(officer => officer.account.address === request.ownerAddress);
const ownerAccount = ValidAccountId.polkadot(request.ownerAddress);
const owner = locSharedState.allLegalOfficers.find(officer => officer.account.equals(ownerAccount));
if(!owner) {
throw new Error("LOC owner is not a registered legal officer");
}
Expand Down Expand Up @@ -815,6 +818,8 @@ export abstract class LocRequestState extends State {
} else if (legalOfficerCase.closed) {
if (legalOfficerCase.locType === 'Collection') {
return new ClosedCollectionLoc(locSharedState, request, legalOfficerCase, locIssuers, invitedContributors);
} else if (legalOfficerCase.locType === 'Identity') {
return new ClosedIdentityLoc(locSharedState, request, legalOfficerCase, locIssuers, invitedContributors);
} else {
return new ClosedLoc(locSharedState, request, legalOfficerCase, locIssuers, invitedContributors);
}
Expand Down Expand Up @@ -2063,6 +2068,30 @@ export class ClosedLoc extends LocRequestState {
}
}

export class ClosedIdentityLoc extends ClosedLoc {

get secrets(): Secret[] {
return Object.values(this._secrets);
}

addSecret(secret: Secret) {
this._secrets[secret.name] = secret;
}

removeSecret(name: string) {
delete this._secrets[name];
}

override async refresh(): Promise<ClosedIdentityLoc | VoidedLoc> {
return await super.refresh() as ClosedIdentityLoc | VoidedLoc;
}

override withLocs(locsState: LocsState): ClosedIdentityLoc {
return this._withLocs(locsState, ClosedIdentityLoc);
}

}

export class LegalOfficerClosedLocCommands extends LegalOfficerNonVoidedCommandsImpl {

async nominateIssuer(params: BasicBlockchainSubmission): Promise<ClosedLoc> {
Expand Down
5 changes: 5 additions & 0 deletions packages/client/src/LocClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ export interface CheckTokensRecordDeliveryRequest {
hash: Hash;
}

export interface Secret {
name: string;
value: string;
}

export class LocMultiClient {

static newLocMultiClient(sharedState: SharedState): LocMultiClient {
Expand Down
2 changes: 2 additions & 0 deletions packages/client/test/Loc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
HashOrContent,
LegalOfficer,
ClosedCollectionLoc,
ClosedIdentityLoc,
ClosedLoc,
LocData,
LocRequestState,
Expand Down Expand Up @@ -368,6 +369,7 @@ describe("ClosedLoc", () => {

it("can nominate issuer", async () => {
const closedLoc = await getClosedIdentityLoc();
expect(closedLoc).toBeInstanceOf(ClosedIdentityLoc)
const signer = new Mock<Signer>();
signer.setup(instance => instance.signAndSend(It.Is<SignParameters>(params => params.signerId.equals(REQUESTER)))).returnsAsync(SUCCESSFUL_SUBMISSION);

Expand Down

0 comments on commit f29e6b8

Please sign in to comment.