Skip to content

Commit

Permalink
web: align provider api with other sdks, fix tests (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmarkovski authored Mar 16, 2022
1 parent b150d6f commit 00637a4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
12 changes: 6 additions & 6 deletions web/src/AccountService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
SignInResponse,
TokenProtection,
} from "./proto";
import {BlindOberonTokenRequest, Oberon, UnBlindOberonTokenRequest} from "@trinsic/okapi";
import { BlindOberonTokenRequest, Oberon, UnBlindOberonTokenRequest } from "@trinsic/okapi";
import { fromUint8Array } from "js-base64";


Expand All @@ -37,11 +37,11 @@ export class AccountService extends ServiceBase {
if (error || response.getStatus() != ResponseStatus.SUCCESS) {
reject(error);
} else {
var authToken = fromUint8Array(response.getProfile()!.serializeBinary());

// set the auth token as active for the current service instance
this.options.setAuthToken(authToken);

var authToken = fromUint8Array(response.getProfile()!.serializeBinary(), true);
if (!response.getProfile()?.getProtection()?.getEnabled() || true) {
// set the auth token as active for the current service instance
this.options.setAuthToken(authToken);
}
resolve(authToken);
}
});
Expand Down
11 changes: 9 additions & 2 deletions web/src/ProviderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import ServiceBase from "./ServiceBase";
import {
CreateEcosystemRequest,
CreateEcosystemResponse,
Ecosystem,
InvitationStatusRequest,
InvitationStatusResponse,
InviteRequest,
InviteResponse,
ProviderClient,
ServiceOptions
} from "./proto";
import { fromUint8Array } from "js-base64";

export class ProviderService extends ServiceBase {
client: ProviderClient;
Expand Down Expand Up @@ -43,13 +45,18 @@ export class ProviderService extends ServiceBase {
});
}

public createEcosystem(request: CreateEcosystemRequest): Promise<CreateEcosystemResponse> {
public createEcosystem(request: CreateEcosystemRequest): Promise<[Ecosystem, string]> {
return new Promise(async (resolve, reject) => {
this.client.createEcosystem(request, null, (error, response) => {
if (error) {
reject(error);
} else {
resolve(response);
var authToken = fromUint8Array(response.getProfile()!.serializeBinary(), true);
if (!response.getProfile()?.getProtection()?.getEnabled() || true) {
// set the auth token as active for the current service instance
this.options.setAuthToken(authToken);
}
resolve([response.getEcosystem()!, authToken]);
}
});
});
Expand Down
15 changes: 13 additions & 2 deletions web/test/WalletService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ import {
InsertItemRequest,
CreateProofRequest,
VerifyProofRequest,
ProviderService,
CreateEcosystemRequest,
} from "../lib";
import { options } from "./env";

/**
* @type {ProviderService} Provider Service
*/
let providerService;
/**
* @type {AccountService} Account Service
*/
Expand All @@ -42,15 +48,20 @@ describe("wallet service tests", () => {
walletService = new WalletService(options);
credentialService = new CredentialService(options);
templateService = new TemplateService(options);

console.log("before all ran");
});

it("can retrieve account info", async () => {
const info = await accountService.info(new InfoRequest());
expect(info).not.toBeNull();
});

if("can create new ecosystem", async () => {
const [ecosystem, authToken] = await providerService.createEcosystem(new CreateEcosystemRequest());

expect(ecosystem).not.toBeNull();
expect(authToken).not.toBeEmpty();
});

it("Demo: create wallet, set profile, search records, issue credential", async () => {
let unsignedDocument = {
"@context": "https://w3id.org/security/v3-unstable",
Expand Down
3 changes: 3 additions & 0 deletions web/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ module.exports = {
experiments: {
asyncWebAssembly: true,
},
stats: {
errorDetails: true
}
};

0 comments on commit 00637a4

Please sign in to comment.