Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: gen zome fn bindings (#75) #78

Merged
merged 1 commit into from
Aug 7, 2024
Merged
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
91 changes: 91 additions & 0 deletions package-lock.json

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

75 changes: 28 additions & 47 deletions packages/authority/src/evm-bytes-signer/evm-bytes-signer-client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type { AppWebsocket, AppSignal } from "@holochain/client";
import {
LocalHoloomSignal,
ResolveEvmSignatureOverRecipeExecutionRequestPayload,
RejectEvmSignatureOverRecipeExecutionRequestPayload,
} from "@holoom/types";
import type { AppSignal, AppClient } from "@holochain/client";
import { LocalHoloomSignal, UsernameRegistryCoordinator } from "@holoom/types";
import { BytesSigner } from "./bytes-signer.js";

export type PickByType<T, K> = T extends { type: K } ? T : never;
Expand All @@ -13,35 +9,15 @@ type EvmSignatureRequested = PickByType<
>;

export class EvmBytesSignerClient {
private usernameRegistryCoordinator: UsernameRegistryCoordinator;
constructor(
readonly appAgent: AppWebsocket,
appClient: AppClient,
readonly bytesSigner: BytesSigner
) {
appAgent.on("signal", (signal) => this.handleAppSignal(signal));
}

async confirmRequest(
payload: ResolveEvmSignatureOverRecipeExecutionRequestPayload
): Promise<void> {
console.log("confirmRequest", payload);
await this.appAgent.callZome({
role_name: "holoom",
zome_name: "username_registry",
fn_name: "resolve_evm_signature_over_recipe_execution_request",
payload,
});
}

async rejectRequest(
payload: RejectEvmSignatureOverRecipeExecutionRequestPayload
): Promise<void> {
console.log("rejectRequest", payload);
await this.appAgent.callZome({
role_name: "holoom",
zome_name: "username_registry",
fn_name: "reject_evm_signature_over_recipe_execution_request",
payload,
});
this.usernameRegistryCoordinator = new UsernameRegistryCoordinator(
appClient
);
appClient.on("signal", (signal) => this.handleAppSignal(signal));
}

handleAppSignal(signal: AppSignal) {
Expand All @@ -60,23 +36,28 @@ export class EvmBytesSignerClient {
signal.u256_array
);
// Will node complain about this orphaned promise?
this.confirmRequest({
request_id: signal.request_id,
requestor: signal.requestor_pubkey,
signed_u256_array: {
signature,
signer: this.bytesSigner.address,
raw: signal.u256_array,
},
});
console.log(`Signed request ${signal.request_id}`);
this.usernameRegistryCoordinator.resolveEvmSignatureOverRecipeExecutionRequest(
{
request_id: signal.request_id,
requestor: signal.requestor_pubkey,
signed_u256_array: {
signature,
signer: this.bytesSigner.address,
raw: signal.u256_array,
},
}
);
} catch (err) {
console.error(err);
console.error(`Rejected request ${signal.request_id}`, err);
// Will node complain about this orphaned promise?
this.rejectRequest({
request_id: signal.request_id,
requestor: signal.requestor_pubkey,
reason: unknownErrToString(err),
});
this.usernameRegistryCoordinator.rejectEvmSignatureOverRecipeExecutionRequest(
{
request_id: signal.request_id,
requestor: signal.requestor_pubkey,
reason: unknownErrToString(err),
}
);
}
}
}
Expand Down
43 changes: 21 additions & 22 deletions packages/authority/src/evm-bytes-signer/offer-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ import {
CreateEvmSigningOfferPayload,
EvmSigningOffer,
EvmU256Item,
RecordsCoordinator,
UsernameRegistryCoordinator,
} from "@holoom/types";
import { BytesSigner } from "./bytes-signer";

export class OfferCreator {
private usernameRegistryCoordinator: UsernameRegistryCoordinator;
private recordsCoordinator: RecordsCoordinator;
constructor(
readonly appClient: AppClient,
appClient: AppClient,
readonly bytesSigner: BytesSigner
) {}
) {
this.usernameRegistryCoordinator = new UsernameRegistryCoordinator(
appClient
);
this.recordsCoordinator = new RecordsCoordinator(appClient);
}

async createOffer(
identifier: string,
Expand All @@ -26,20 +35,15 @@ export class OfferCreator {
await this.untilRecipeGossiped(offer.recipe_ah);

const signature = await this.bytesSigner.sign_offer(offer);
const payload: CreateEvmSigningOfferPayload = {
identifier,
signed_offer: {
signer: this.bytesSigner.address,
signature,
offer,
},
};
const record: Record = await this.appClient.callZome({
role_name: "holoom",
zome_name: "username_registry",
fn_name: "create_signed_evm_signing_offer",
payload,
});
const record: Record =
await this.usernameRegistryCoordinator.createSignedEvmSigningOffer({
identifier,
signed_offer: {
signer: this.bytesSigner.address,
signature,
offer,
},
});
console.log("Created record", record);
const actionHash = Array.from(record.signed_action.hashed.hash);
return actionHash;
Expand All @@ -48,12 +52,7 @@ export class OfferCreator {
private async untilRecipeGossiped(recipeAh: ActionHash) {
const deadline = Date.now() + 10_000;
while (Date.now() < deadline) {
const record: Record = await this.appClient.callZome({
role_name: "holoom",
zome_name: "records",
fn_name: "get_record",
payload: recipeAh,
});
const record = await this.recordsCoordinator.getRecord(recipeAh);
if (record) return;
await new Promise((r) => setTimeout(r, 500));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type { AppWebsocket, AppSignal } from "@holochain/client";
import {
ConfirmExternalIdRequestPayload,
LocalHoloomSignal,
RejectExternalIdRequestPayload,
} from "@holoom/types";
import type { AppSignal, AppClient } from "@holochain/client";
import { LocalHoloomSignal, UsernameRegistryCoordinator } from "@holoom/types";
import { AccessTokenAssessor } from "./access-token-assessor.js";

type PickByType<T, K> = T extends { type: K } ? T : never;
Expand All @@ -13,33 +9,15 @@ type ExternalIdAttestationRequested = PickByType<
>;

export class ExternalIdAttestorClient {
private usernameRegistryCoordinator: UsernameRegistryCoordinator;
constructor(
readonly appAgent: AppWebsocket,
appClient: AppClient,
readonly accessTokenAssessor: AccessTokenAssessor
) {
appAgent.on("signal", (signal) => this.handleAppSignal(signal));
}

async confirmRequest(
payload: ConfirmExternalIdRequestPayload
): Promise<void> {
console.log("confirmRequest", payload);
await this.appAgent.callZome({
role_name: "holoom",
zome_name: "username_registry",
fn_name: "confirm_external_id_request",
payload,
});
}

async rejectRequest(payload: RejectExternalIdRequestPayload): Promise<void> {
console.log("rejectRequest", payload);
await this.appAgent.callZome({
role_name: "holoom",
zome_name: "username_registry",
fn_name: "reject_external_id_request",
payload,
});
this.usernameRegistryCoordinator = new UsernameRegistryCoordinator(
appClient
);
appClient.on("signal", (signal) => this.handleAppSignal(signal));
}

handleAppSignal(signal: AppSignal) {
Expand All @@ -63,16 +41,17 @@ export class ExternalIdAttestorClient {
const { externalId, displayName } =
await this.accessTokenAssessor.fetchUserInfo(accessToken);
// Will node complain about this orphaned promise?
this.confirmRequest({
console.log(`Confirmed request ${signal.request_id}`);
this.usernameRegistryCoordinator.confirmExternalIdRequest({
request_id: signal.request_id,
requestor: signal.requestor_pubkey,
external_id: externalId,
display_name: displayName,
});
} catch (err) {
console.error(err);
console.error(`Rejected request ${signal.request_id}`, err);
// Will node complain about this orphaned promise?
this.rejectRequest({
this.usernameRegistryCoordinator.rejectExternalIdRequest({
request_id: signal.request_id,
requestor: signal.requestor_pubkey,
reason: unknownErrToString(err),
Expand Down
Loading
Loading