From 55c032d5c34d2cb56f762a985bf45753f45803c9 Mon Sep 17 00:00:00 2001 From: 8e8b2c <8e8b2c@proton.me> Date: Tue, 6 Aug 2024 15:57:38 +0100 Subject: [PATCH 1/3] feat: generate zome function TS bindings --- package-lock.json | 91 ++++ packages/types/package.json | 3 +- .../types/scripts/extract-fn-bindings.mjs | 247 ++++++++++ packages/types/scripts/prepare-bindings.mjs | 4 +- packages/types/src/index.ts | 35 +- .../src/{ => types}/ChainWalletSignature.ts | 0 .../ConfirmExternalIdRequestPayload.ts | 0 .../CreateEvmSigningOfferPayload.ts | 0 .../src/{ => types}/DocumentRelationTag.ts | 0 .../EvmSignatureOverRecipeExecutionRequest.ts | 0 .../types/src/{ => types}/EvmSigningOffer.ts | 0 packages/types/src/{ => types}/EvmU256Item.ts | 0 .../src/{ => types}/ExecuteRecipePayload.ts | 0 .../src/{ => types}/ExternalIdAttestation.ts | 0 .../GetMetadataItemValuePayload.ts | 0 ...gestExternalIdAttestationRequestPayload.ts | 0 .../{ => types}/JqInstructionArgumentNames.ts | 0 .../src/{ => types}/LocalHoloomSignal.ts | 0 .../types/src/{ => types}/MetadataItem.ts | 0 .../types/src/{ => types}/OracleDocument.ts | 0 packages/types/src/{ => types}/Recipe.ts | 0 .../types/src/{ => types}/RecipeArgument.ts | 0 .../src/{ => types}/RecipeArgumentType.ts | 0 .../types/src/{ => types}/RecipeExecution.ts | 0 .../src/{ => types}/RecipeInstruction.ts | 0 .../{ => types}/RecipeInstructionExecution.ts | 0 ...natureOverRecipeExecutionRequestPayload.ts | 0 .../RejectExternalIdRequestPayload.ts | 0 .../src/{ => types}/RemoteHoloomSignal.ts | 0 ...natureOverRecipeExecutionRequestPayload.ts | 0 ...SendExternalIdAttestationRequestPayload.ts | 0 .../types/src/{ => types}/SignableBytes.ts | 0 .../src/{ => types}/SignedEvmSigningOffer.ts | 0 .../src/{ => types}/SignedEvmU256Array.ts | 0 .../types/src/{ => types}/SignedUsername.ts | 0 .../{ => types}/UpdateMetadataItemPayload.ts | 0 .../src/{ => types}/UsernameAttestation.ts | 0 .../src/{ => types}/WalletAttestation.ts | 0 packages/types/src/types/index.ts | 33 ++ .../src/zome-functions/PingCoordinator.ts | 18 + .../src/zome-functions/RecordsCoordinator.ts | 18 + .../src/zome-functions/SignerCoordinator.ts | 19 + .../UsernameRegistryCoordinator.ts | 452 ++++++++++++++++++ packages/types/src/zome-functions/index.ts | 4 + 44 files changed, 888 insertions(+), 36 deletions(-) create mode 100644 packages/types/scripts/extract-fn-bindings.mjs rename packages/types/src/{ => types}/ChainWalletSignature.ts (100%) rename packages/types/src/{ => types}/ConfirmExternalIdRequestPayload.ts (100%) rename packages/types/src/{ => types}/CreateEvmSigningOfferPayload.ts (100%) rename packages/types/src/{ => types}/DocumentRelationTag.ts (100%) rename packages/types/src/{ => types}/EvmSignatureOverRecipeExecutionRequest.ts (100%) rename packages/types/src/{ => types}/EvmSigningOffer.ts (100%) rename packages/types/src/{ => types}/EvmU256Item.ts (100%) rename packages/types/src/{ => types}/ExecuteRecipePayload.ts (100%) rename packages/types/src/{ => types}/ExternalIdAttestation.ts (100%) rename packages/types/src/{ => types}/GetMetadataItemValuePayload.ts (100%) rename packages/types/src/{ => types}/IngestExternalIdAttestationRequestPayload.ts (100%) rename packages/types/src/{ => types}/JqInstructionArgumentNames.ts (100%) rename packages/types/src/{ => types}/LocalHoloomSignal.ts (100%) rename packages/types/src/{ => types}/MetadataItem.ts (100%) rename packages/types/src/{ => types}/OracleDocument.ts (100%) rename packages/types/src/{ => types}/Recipe.ts (100%) rename packages/types/src/{ => types}/RecipeArgument.ts (100%) rename packages/types/src/{ => types}/RecipeArgumentType.ts (100%) rename packages/types/src/{ => types}/RecipeExecution.ts (100%) rename packages/types/src/{ => types}/RecipeInstruction.ts (100%) rename packages/types/src/{ => types}/RecipeInstructionExecution.ts (100%) rename packages/types/src/{ => types}/RejectEvmSignatureOverRecipeExecutionRequestPayload.ts (100%) rename packages/types/src/{ => types}/RejectExternalIdRequestPayload.ts (100%) rename packages/types/src/{ => types}/RemoteHoloomSignal.ts (100%) rename packages/types/src/{ => types}/ResolveEvmSignatureOverRecipeExecutionRequestPayload.ts (100%) rename packages/types/src/{ => types}/SendExternalIdAttestationRequestPayload.ts (100%) rename packages/types/src/{ => types}/SignableBytes.ts (100%) rename packages/types/src/{ => types}/SignedEvmSigningOffer.ts (100%) rename packages/types/src/{ => types}/SignedEvmU256Array.ts (100%) rename packages/types/src/{ => types}/SignedUsername.ts (100%) rename packages/types/src/{ => types}/UpdateMetadataItemPayload.ts (100%) rename packages/types/src/{ => types}/UsernameAttestation.ts (100%) rename packages/types/src/{ => types}/WalletAttestation.ts (100%) create mode 100644 packages/types/src/types/index.ts create mode 100644 packages/types/src/zome-functions/PingCoordinator.ts create mode 100644 packages/types/src/zome-functions/RecordsCoordinator.ts create mode 100644 packages/types/src/zome-functions/SignerCoordinator.ts create mode 100644 packages/types/src/zome-functions/UsernameRegistryCoordinator.ts create mode 100644 packages/types/src/zome-functions/index.ts diff --git a/package-lock.json b/package-lock.json index c9de4af..158c869 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10361,6 +10361,7 @@ "@rollup/plugin-alias": "^5.1.0", "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-typescript": "^11.1.6", + "glob": "^11.0.0", "prettier": "^3.3.3", "rimraf": "^5.0.5", "rollup": "^4.12.0", @@ -10390,6 +10391,96 @@ "engines": { "node": ">=18.0.0 || >=20.0.0" } + }, + "packages/types/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "packages/types/node_modules/glob": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-11.0.0.tgz", + "integrity": "sha512-9UiX/Bl6J2yaBbxKoEBRm4Cipxgok8kQYcOPEhScPwebu2I0HoQOuYdIO6S3hLuWoZgpDpwQZMzTFxgpkyT76g==", + "dev": true, + "dependencies": { + "foreground-child": "^3.1.0", + "jackspeak": "^4.0.1", + "minimatch": "^10.0.0", + "minipass": "^7.1.2", + "package-json-from-dist": "^1.0.0", + "path-scurry": "^2.0.0" + }, + "bin": { + "glob": "dist/esm/bin.mjs" + }, + "engines": { + "node": "20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "packages/types/node_modules/jackspeak": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-4.0.1.tgz", + "integrity": "sha512-cub8rahkh0Q/bw1+GxP7aeSe29hHHn2V4m29nnDlvCdlgU+3UGxkZp7Z53jLUdpX3jdTO0nJZUDl3xvbWc2Xog==", + "dev": true, + "dependencies": { + "@isaacs/cliui": "^8.0.2" + }, + "engines": { + "node": "20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + }, + "optionalDependencies": { + "@pkgjs/parseargs": "^0.11.0" + } + }, + "packages/types/node_modules/lru-cache": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.0.0.tgz", + "integrity": "sha512-Qv32eSV1RSCfhY3fpPE2GNZ8jgM9X7rdAfemLWqTUxwiyIC4jJ6Sy0fZ8H+oLWevO6i4/bizg7c8d8i6bxrzbA==", + "dev": true, + "engines": { + "node": "20 || >=22" + } + }, + "packages/types/node_modules/minimatch": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.0.1.tgz", + "integrity": "sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": "20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "packages/types/node_modules/path-scurry": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-2.0.0.tgz", + "integrity": "sha512-ypGJsmGtdXUOeM5u93TyeIEfEhM6s+ljAhrk5vAvSx8uyY/02OvrZnA0YNGUrPXfpJMgI1ODd3nwz8Npx4O4cg==", + "dev": true, + "dependencies": { + "lru-cache": "^11.0.0", + "minipass": "^7.1.2" + }, + "engines": { + "node": "20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } } } } diff --git a/packages/types/package.json b/packages/types/package.json index bf9cfa7..1200091 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -30,7 +30,7 @@ }, "scripts": { "build": "npm run prepare:bindings && rimraf dist && npm run build:browser && npm run build:node", - "prepare:bindings": "rimraf src/* && node scripts/prepare-bindings.mjs", + "prepare:bindings": "rimraf src/types/* && node scripts/prepare-bindings.mjs && rimraf src/zome-functions/* && node scripts/extract-fn-bindings.mjs", "build:browser": "rollup -c rollup.browser.config.ts --configPlugin typescript", "build:node": "rollup -c rollup.node.config.ts --configPlugin typescript" }, @@ -42,6 +42,7 @@ "@rollup/plugin-alias": "^5.1.0", "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-typescript": "^11.1.6", + "glob": "^11.0.0", "prettier": "^3.3.3", "rimraf": "^5.0.5", "rollup": "^4.12.0", diff --git a/packages/types/scripts/extract-fn-bindings.mjs b/packages/types/scripts/extract-fn-bindings.mjs new file mode 100644 index 0000000..02fd849 --- /dev/null +++ b/packages/types/scripts/extract-fn-bindings.mjs @@ -0,0 +1,247 @@ +import fs from "fs/promises"; +import { glob } from "glob"; +import prettier from "prettier"; + +const CRATES_DIR = "../../crates"; +const coordinator_regex = /^.+_coordinator$/; + +async function main() { + const crates = await fs.readdir(CRATES_DIR); + const typesTransform = await TypeTransform.init(); + const classNames = await Promise.all( + crates + .filter((name) => coordinator_regex.test(name)) + .map((name) => extractFnBindingsForCrate(name, typesTransform)) + ); + + classNames.sort(); + let indexContent = classNames + .map((className) => `export * from "./${className}";\n`) + .join(""); + indexContent = await prettier.format(indexContent, { parser: "typescript" }); + fs.writeFile("./src/zome-functions/index.ts", indexContent); +} + +const extern_regex = + /#\[hdk_extern\]\n(pub )?fn (\w+)?\(\s*(\w+): (\(\)|\w+),?\n?\) -> ExternResult<(.+)> \{/g; + +const SKIPPED_METHODS = ["init", "recv_remote_signal"]; + +async function extractFnBindingsForCrate(name, typesTransform) { + console.log("Start extracting fn bindings for:", name); + const rustFiles = await glob(`${CRATES_DIR}/${name}/src/**/*.rs`); + const bindings = []; + let deps = new Set(); + await Promise.all( + rustFiles.map(async (filePath) => { + const content = await fs.readFile(filePath, "utf-8"); + const matches = content.matchAll(extern_regex); + for (const match of matches) { + const [ + _fullMatch, + _pub, + fnName, + inputName, + rustInputType, + rustOutputType, + ] = match; + if (SKIPPED_METHODS.includes(fnName)) { + continue; + } + try { + const { type: inputType, deps: inputDeps } = + typesTransform.transform(rustInputType); + const { type: outputType, deps: outputDeps } = + typesTransform.transform(rustOutputType); + deps = new Set([...inputDeps, ...outputDeps, ...deps]); + bindings.push({ + fnName, + inputName, + inputType, + outputType, + }); + } catch (err) { + console.log("Failed:", fnName); + // console.error("Skipped", fnName, err); + } + } + }) + ); + bindings.sort((x1, x2) => (x1.fnName < x2.fnName ? -1 : 1)); + + const methodStrs = bindings.map((binding) => { + if (binding.inputType === "void") { + return `async ${snakeToCamel(binding.fnName)}(): Promise<${binding.outputType}> { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "${binding.fnName}", + payload: null, + }) + }`; + } else { + return `async ${snakeToCamel(binding.fnName)}(payload: ${binding.inputType}): Promise<${binding.outputType}> { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "${binding.fnName}", + payload, + }) + }`; + } + }); + + const splitDeps = { holochain: ["AppClient"], holoom: [] }; + for (const dep of deps) { + const [location, name] = dep.split(":"); + splitDeps[location].push(name); + } + + let classFile = `import {${splitDeps.holochain.join(", ")}} from '@holochain/client';\n`; + if (splitDeps.holoom.length) { + classFile += `import {${splitDeps.holoom.join(", ")}} from '../types';\n`; + } + const className = snakeToUpperCamel(name); + classFile += ` + export class ${className} { + constructor( + private readonly client: AppClient, + private readonly roleName = 'holoom', + private readonly zomeName = '${name}', + ) {} + + ${methodStrs.join("\n\n")} + } + `; + + classFile = await prettier.format(classFile, { parser: "typescript" }); + await fs.writeFile(`./src/zome-functions/${className}.ts`, classFile); + return className; +} + +const snakeToCamel = (str) => + str + .toLowerCase() + .replace(/([-_][a-z])/g, (group) => + group.toUpperCase().replace("-", "").replace("_", "") + ); +const snakeToUpperCamel = (str) => { + str = snakeToCamel(str); + return str.charAt(0).toUpperCase() + str.slice(1); +}; + +const HOLOCHAIN_TYPES = ["ActionHash", "AgentPubKey", "Record", "Signature"]; + +class TypeTransform { + static async init() { + const tsFiles = await fs.readdir(`${CRATES_DIR}/holoom_types/bindings`); + const holoomTypes = tsFiles.map((name) => name.slice(0, -3)); + const transform = new TypeTransform(); + transform.holoomTypes = holoomTypes; + return transform; + } + + transform(rustType) { + const withDelimiters = rustType.replace(/([a-z0-9]+|[^\w])/gi, "$1†"); + const parts = withDelimiters + .split("†") + .map((str) => str.trim()) + .filter((str) => !!str); + // console.log("parts", parts, rustType, withDelimiters); + if (parts.length === 0) { + throw Error("Empty rust type"); + } + if (parts.length === 1) { + return this.transformShallow(rustType); + } + // Type is complex + + if (parts[0] === "(") { + // Found a tuple or Unit type + if (parts[parts.length - 1] !== ")") { + throw new Error(`Invalid type ${rustType}`); + } + if (parts.length === 2) { + // Rust unit type + return { type: "void", deps: new Set() }; + } + // Found tuple + const { types, deps } = this.transformElemsFromParts(parts.slice(1, -1)); + return { type: `[${types.join(", ")}]`, deps }; + } + + if (parts[1] === "<") { + // Found a generic + if (parts[parts.length - 1] !== ">") { + throw new Error(`Invalid type ${rustType}`); + } + + const { types, deps } = this.transformElemsFromParts(parts.slice(2, -1)); + + if (parts[0] === "Vec") { + if (types.length !== 1) { + throw new Error(`Invalid Vec '${rustType}'`); + } + return { type: `${types[0]}[]`, deps }; + } else if (parts[0] === "Option") { + if (types.length !== 1) { + throw new Error(`Invalid Option '${rustType}'`); + } + return { type: `(${types[0]}) | null`, deps }; + } else if (parts[0] === "HashMap") { + if (types.length !== 2) { + throw new Error(`Invalid HashMap '${rustType}'`); + } + return { + type: `{[key: ${types[0]}]: ${types[1]}}`, + deps, + }; + } + } + throw new Error(`Type not determined for '${rustType}'`); + } + + transformElemsFromParts(parts) { + const rustElems = parts + .join("") + .split(/,\s*?/) + .filter((str) => !!str); // Protects against trailing comma + const tsElems = rustElems.map((elem) => this.transform(elem)); + const deps = tsElems.reduce( + (acc, elem) => new Set([...elem.deps, ...acc]), + new Set() + ); + const types = tsElems.map((elem) => elem.type); + + return { types, deps }; + } + + transformShallow(rustType) { + if (HOLOCHAIN_TYPES.includes(rustType)) { + return { type: rustType, deps: new Set([`holochain:${rustType}`]) }; + } else if (this.holoomTypes.includes(rustType)) { + return { type: rustType, deps: new Set([`holoom:${rustType}`]) }; + } + const type = (() => { + switch (rustType) { + case "String": + return "string"; + case "bool": + return "boolean"; + case "EvmAddress": + return "Uint8Array"; + case "EvmSignature": + return "[Uint8Array, Uint8Array, number]"; + case "SolanaAddress": + return "Uint8Array"; + case "SolanaSignature": + return "number[]"; + default: + throw new Error(`Unknown type ${rustType}`); + } + })(); + return { type, deps: new Set() }; + } +} + +main().catch(console.error); diff --git a/packages/types/scripts/prepare-bindings.mjs b/packages/types/scripts/prepare-bindings.mjs index 7492bd3..eb4047e 100644 --- a/packages/types/scripts/prepare-bindings.mjs +++ b/packages/types/scripts/prepare-bindings.mjs @@ -18,14 +18,14 @@ async function main() { content = importLine + content; } content = await prettier.format(content, { parser: "typescript" }); - fs.writeFile(`./src/${file}`, content); + fs.writeFile(`./src/types/${file}`, content); } let indexContent = files .map((file) => `export * from "./${file.slice(0, -3)}";\n`) .join(""); indexContent = await prettier.format(indexContent, { parser: "typescript" }); - fs.writeFile("./src/index.ts", indexContent); + fs.writeFile("./src/types/index.ts", indexContent); } main(); diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 9ad428a..94c610c 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -1,33 +1,2 @@ -export * from "./ChainWalletSignature"; -export * from "./ConfirmExternalIdRequestPayload"; -export * from "./CreateEvmSigningOfferPayload"; -export * from "./DocumentRelationTag"; -export * from "./EvmSignatureOverRecipeExecutionRequest"; -export * from "./EvmSigningOffer"; -export * from "./EvmU256Item"; -export * from "./ExecuteRecipePayload"; -export * from "./ExternalIdAttestation"; -export * from "./GetMetadataItemValuePayload"; -export * from "./IngestExternalIdAttestationRequestPayload"; -export * from "./JqInstructionArgumentNames"; -export * from "./LocalHoloomSignal"; -export * from "./MetadataItem"; -export * from "./OracleDocument"; -export * from "./Recipe"; -export * from "./RecipeArgument"; -export * from "./RecipeArgumentType"; -export * from "./RecipeExecution"; -export * from "./RecipeInstruction"; -export * from "./RecipeInstructionExecution"; -export * from "./RejectEvmSignatureOverRecipeExecutionRequestPayload"; -export * from "./RejectExternalIdRequestPayload"; -export * from "./RemoteHoloomSignal"; -export * from "./ResolveEvmSignatureOverRecipeExecutionRequestPayload"; -export * from "./SendExternalIdAttestationRequestPayload"; -export * from "./SignableBytes"; -export * from "./SignedEvmSigningOffer"; -export * from "./SignedEvmU256Array"; -export * from "./SignedUsername"; -export * from "./UpdateMetadataItemPayload"; -export * from "./UsernameAttestation"; -export * from "./WalletAttestation"; +export * from "./types"; +export * from "./zome-functions"; diff --git a/packages/types/src/ChainWalletSignature.ts b/packages/types/src/types/ChainWalletSignature.ts similarity index 100% rename from packages/types/src/ChainWalletSignature.ts rename to packages/types/src/types/ChainWalletSignature.ts diff --git a/packages/types/src/ConfirmExternalIdRequestPayload.ts b/packages/types/src/types/ConfirmExternalIdRequestPayload.ts similarity index 100% rename from packages/types/src/ConfirmExternalIdRequestPayload.ts rename to packages/types/src/types/ConfirmExternalIdRequestPayload.ts diff --git a/packages/types/src/CreateEvmSigningOfferPayload.ts b/packages/types/src/types/CreateEvmSigningOfferPayload.ts similarity index 100% rename from packages/types/src/CreateEvmSigningOfferPayload.ts rename to packages/types/src/types/CreateEvmSigningOfferPayload.ts diff --git a/packages/types/src/DocumentRelationTag.ts b/packages/types/src/types/DocumentRelationTag.ts similarity index 100% rename from packages/types/src/DocumentRelationTag.ts rename to packages/types/src/types/DocumentRelationTag.ts diff --git a/packages/types/src/EvmSignatureOverRecipeExecutionRequest.ts b/packages/types/src/types/EvmSignatureOverRecipeExecutionRequest.ts similarity index 100% rename from packages/types/src/EvmSignatureOverRecipeExecutionRequest.ts rename to packages/types/src/types/EvmSignatureOverRecipeExecutionRequest.ts diff --git a/packages/types/src/EvmSigningOffer.ts b/packages/types/src/types/EvmSigningOffer.ts similarity index 100% rename from packages/types/src/EvmSigningOffer.ts rename to packages/types/src/types/EvmSigningOffer.ts diff --git a/packages/types/src/EvmU256Item.ts b/packages/types/src/types/EvmU256Item.ts similarity index 100% rename from packages/types/src/EvmU256Item.ts rename to packages/types/src/types/EvmU256Item.ts diff --git a/packages/types/src/ExecuteRecipePayload.ts b/packages/types/src/types/ExecuteRecipePayload.ts similarity index 100% rename from packages/types/src/ExecuteRecipePayload.ts rename to packages/types/src/types/ExecuteRecipePayload.ts diff --git a/packages/types/src/ExternalIdAttestation.ts b/packages/types/src/types/ExternalIdAttestation.ts similarity index 100% rename from packages/types/src/ExternalIdAttestation.ts rename to packages/types/src/types/ExternalIdAttestation.ts diff --git a/packages/types/src/GetMetadataItemValuePayload.ts b/packages/types/src/types/GetMetadataItemValuePayload.ts similarity index 100% rename from packages/types/src/GetMetadataItemValuePayload.ts rename to packages/types/src/types/GetMetadataItemValuePayload.ts diff --git a/packages/types/src/IngestExternalIdAttestationRequestPayload.ts b/packages/types/src/types/IngestExternalIdAttestationRequestPayload.ts similarity index 100% rename from packages/types/src/IngestExternalIdAttestationRequestPayload.ts rename to packages/types/src/types/IngestExternalIdAttestationRequestPayload.ts diff --git a/packages/types/src/JqInstructionArgumentNames.ts b/packages/types/src/types/JqInstructionArgumentNames.ts similarity index 100% rename from packages/types/src/JqInstructionArgumentNames.ts rename to packages/types/src/types/JqInstructionArgumentNames.ts diff --git a/packages/types/src/LocalHoloomSignal.ts b/packages/types/src/types/LocalHoloomSignal.ts similarity index 100% rename from packages/types/src/LocalHoloomSignal.ts rename to packages/types/src/types/LocalHoloomSignal.ts diff --git a/packages/types/src/MetadataItem.ts b/packages/types/src/types/MetadataItem.ts similarity index 100% rename from packages/types/src/MetadataItem.ts rename to packages/types/src/types/MetadataItem.ts diff --git a/packages/types/src/OracleDocument.ts b/packages/types/src/types/OracleDocument.ts similarity index 100% rename from packages/types/src/OracleDocument.ts rename to packages/types/src/types/OracleDocument.ts diff --git a/packages/types/src/Recipe.ts b/packages/types/src/types/Recipe.ts similarity index 100% rename from packages/types/src/Recipe.ts rename to packages/types/src/types/Recipe.ts diff --git a/packages/types/src/RecipeArgument.ts b/packages/types/src/types/RecipeArgument.ts similarity index 100% rename from packages/types/src/RecipeArgument.ts rename to packages/types/src/types/RecipeArgument.ts diff --git a/packages/types/src/RecipeArgumentType.ts b/packages/types/src/types/RecipeArgumentType.ts similarity index 100% rename from packages/types/src/RecipeArgumentType.ts rename to packages/types/src/types/RecipeArgumentType.ts diff --git a/packages/types/src/RecipeExecution.ts b/packages/types/src/types/RecipeExecution.ts similarity index 100% rename from packages/types/src/RecipeExecution.ts rename to packages/types/src/types/RecipeExecution.ts diff --git a/packages/types/src/RecipeInstruction.ts b/packages/types/src/types/RecipeInstruction.ts similarity index 100% rename from packages/types/src/RecipeInstruction.ts rename to packages/types/src/types/RecipeInstruction.ts diff --git a/packages/types/src/RecipeInstructionExecution.ts b/packages/types/src/types/RecipeInstructionExecution.ts similarity index 100% rename from packages/types/src/RecipeInstructionExecution.ts rename to packages/types/src/types/RecipeInstructionExecution.ts diff --git a/packages/types/src/RejectEvmSignatureOverRecipeExecutionRequestPayload.ts b/packages/types/src/types/RejectEvmSignatureOverRecipeExecutionRequestPayload.ts similarity index 100% rename from packages/types/src/RejectEvmSignatureOverRecipeExecutionRequestPayload.ts rename to packages/types/src/types/RejectEvmSignatureOverRecipeExecutionRequestPayload.ts diff --git a/packages/types/src/RejectExternalIdRequestPayload.ts b/packages/types/src/types/RejectExternalIdRequestPayload.ts similarity index 100% rename from packages/types/src/RejectExternalIdRequestPayload.ts rename to packages/types/src/types/RejectExternalIdRequestPayload.ts diff --git a/packages/types/src/RemoteHoloomSignal.ts b/packages/types/src/types/RemoteHoloomSignal.ts similarity index 100% rename from packages/types/src/RemoteHoloomSignal.ts rename to packages/types/src/types/RemoteHoloomSignal.ts diff --git a/packages/types/src/ResolveEvmSignatureOverRecipeExecutionRequestPayload.ts b/packages/types/src/types/ResolveEvmSignatureOverRecipeExecutionRequestPayload.ts similarity index 100% rename from packages/types/src/ResolveEvmSignatureOverRecipeExecutionRequestPayload.ts rename to packages/types/src/types/ResolveEvmSignatureOverRecipeExecutionRequestPayload.ts diff --git a/packages/types/src/SendExternalIdAttestationRequestPayload.ts b/packages/types/src/types/SendExternalIdAttestationRequestPayload.ts similarity index 100% rename from packages/types/src/SendExternalIdAttestationRequestPayload.ts rename to packages/types/src/types/SendExternalIdAttestationRequestPayload.ts diff --git a/packages/types/src/SignableBytes.ts b/packages/types/src/types/SignableBytes.ts similarity index 100% rename from packages/types/src/SignableBytes.ts rename to packages/types/src/types/SignableBytes.ts diff --git a/packages/types/src/SignedEvmSigningOffer.ts b/packages/types/src/types/SignedEvmSigningOffer.ts similarity index 100% rename from packages/types/src/SignedEvmSigningOffer.ts rename to packages/types/src/types/SignedEvmSigningOffer.ts diff --git a/packages/types/src/SignedEvmU256Array.ts b/packages/types/src/types/SignedEvmU256Array.ts similarity index 100% rename from packages/types/src/SignedEvmU256Array.ts rename to packages/types/src/types/SignedEvmU256Array.ts diff --git a/packages/types/src/SignedUsername.ts b/packages/types/src/types/SignedUsername.ts similarity index 100% rename from packages/types/src/SignedUsername.ts rename to packages/types/src/types/SignedUsername.ts diff --git a/packages/types/src/UpdateMetadataItemPayload.ts b/packages/types/src/types/UpdateMetadataItemPayload.ts similarity index 100% rename from packages/types/src/UpdateMetadataItemPayload.ts rename to packages/types/src/types/UpdateMetadataItemPayload.ts diff --git a/packages/types/src/UsernameAttestation.ts b/packages/types/src/types/UsernameAttestation.ts similarity index 100% rename from packages/types/src/UsernameAttestation.ts rename to packages/types/src/types/UsernameAttestation.ts diff --git a/packages/types/src/WalletAttestation.ts b/packages/types/src/types/WalletAttestation.ts similarity index 100% rename from packages/types/src/WalletAttestation.ts rename to packages/types/src/types/WalletAttestation.ts diff --git a/packages/types/src/types/index.ts b/packages/types/src/types/index.ts new file mode 100644 index 0000000..9ad428a --- /dev/null +++ b/packages/types/src/types/index.ts @@ -0,0 +1,33 @@ +export * from "./ChainWalletSignature"; +export * from "./ConfirmExternalIdRequestPayload"; +export * from "./CreateEvmSigningOfferPayload"; +export * from "./DocumentRelationTag"; +export * from "./EvmSignatureOverRecipeExecutionRequest"; +export * from "./EvmSigningOffer"; +export * from "./EvmU256Item"; +export * from "./ExecuteRecipePayload"; +export * from "./ExternalIdAttestation"; +export * from "./GetMetadataItemValuePayload"; +export * from "./IngestExternalIdAttestationRequestPayload"; +export * from "./JqInstructionArgumentNames"; +export * from "./LocalHoloomSignal"; +export * from "./MetadataItem"; +export * from "./OracleDocument"; +export * from "./Recipe"; +export * from "./RecipeArgument"; +export * from "./RecipeArgumentType"; +export * from "./RecipeExecution"; +export * from "./RecipeInstruction"; +export * from "./RecipeInstructionExecution"; +export * from "./RejectEvmSignatureOverRecipeExecutionRequestPayload"; +export * from "./RejectExternalIdRequestPayload"; +export * from "./RemoteHoloomSignal"; +export * from "./ResolveEvmSignatureOverRecipeExecutionRequestPayload"; +export * from "./SendExternalIdAttestationRequestPayload"; +export * from "./SignableBytes"; +export * from "./SignedEvmSigningOffer"; +export * from "./SignedEvmU256Array"; +export * from "./SignedUsername"; +export * from "./UpdateMetadataItemPayload"; +export * from "./UsernameAttestation"; +export * from "./WalletAttestation"; diff --git a/packages/types/src/zome-functions/PingCoordinator.ts b/packages/types/src/zome-functions/PingCoordinator.ts new file mode 100644 index 0000000..dbcdd9c --- /dev/null +++ b/packages/types/src/zome-functions/PingCoordinator.ts @@ -0,0 +1,18 @@ +import { AppClient } from "@holochain/client"; + +export class PingCoordinator { + constructor( + private readonly client: AppClient, + private readonly roleName = "holoom", + private readonly zomeName = "ping_coordinator", + ) {} + + async ping(): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "ping", + payload: null, + }); + } +} diff --git a/packages/types/src/zome-functions/RecordsCoordinator.ts b/packages/types/src/zome-functions/RecordsCoordinator.ts new file mode 100644 index 0000000..dd41d86 --- /dev/null +++ b/packages/types/src/zome-functions/RecordsCoordinator.ts @@ -0,0 +1,18 @@ +import { AppClient, ActionHash, Record } from "@holochain/client"; + +export class RecordsCoordinator { + constructor( + private readonly client: AppClient, + private readonly roleName = "holoom", + private readonly zomeName = "records_coordinator", + ) {} + + async getRecord(payload: ActionHash): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_record", + payload, + }); + } +} diff --git a/packages/types/src/zome-functions/SignerCoordinator.ts b/packages/types/src/zome-functions/SignerCoordinator.ts new file mode 100644 index 0000000..9c53bc6 --- /dev/null +++ b/packages/types/src/zome-functions/SignerCoordinator.ts @@ -0,0 +1,19 @@ +import { AppClient, Signature } from "@holochain/client"; +import { SignableBytes } from "../types"; + +export class SignerCoordinator { + constructor( + private readonly client: AppClient, + private readonly roleName = "holoom", + private readonly zomeName = "signer_coordinator", + ) {} + + async signMessage(payload: SignableBytes): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "sign_message", + payload, + }); + } +} diff --git a/packages/types/src/zome-functions/UsernameRegistryCoordinator.ts b/packages/types/src/zome-functions/UsernameRegistryCoordinator.ts new file mode 100644 index 0000000..f8249b0 --- /dev/null +++ b/packages/types/src/zome-functions/UsernameRegistryCoordinator.ts @@ -0,0 +1,452 @@ +import { AppClient, ActionHash, Record, AgentPubKey } from "@holochain/client"; +import { + RejectEvmSignatureOverRecipeExecutionRequestPayload, + ResolveEvmSignatureOverRecipeExecutionRequestPayload, + EvmSignatureOverRecipeExecutionRequest, + CreateEvmSigningOfferPayload, + ExternalIdAttestation, + RejectExternalIdRequestPayload, + ConfirmExternalIdRequestPayload, + IngestExternalIdAttestationRequestPayload, + SendExternalIdAttestationRequestPayload, + DocumentRelationTag, + OracleDocument, + Recipe, + ExecuteRecipePayload, + RecipeExecution, + SignedUsername, + UsernameAttestation, + WalletAttestation, + ChainWalletSignature, + GetMetadataItemValuePayload, + UpdateMetadataItemPayload, +} from "../types"; + +export class UsernameRegistryCoordinator { + constructor( + private readonly client: AppClient, + private readonly roleName = "holoom", + private readonly zomeName = "username_registry_coordinator", + ) {} + + async attestWalletSignature(payload: ChainWalletSignature): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "attest_wallet_signature", + payload, + }); + } + + async confirmExternalIdRequest( + payload: ConfirmExternalIdRequestPayload, + ): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "confirm_external_id_request", + payload, + }); + } + + async createExternalIdAttestation( + payload: ExternalIdAttestation, + ): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "create_external_id_attestation", + payload, + }); + } + + async createOracleDocument(payload: OracleDocument): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "create_oracle_document", + payload, + }); + } + + async createRecipe(payload: Recipe): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "create_recipe", + payload, + }); + } + + async createRecipeExecution(payload: RecipeExecution): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "create_recipe_execution", + payload, + }); + } + + async createSignedEvmSigningOffer( + payload: CreateEvmSigningOfferPayload, + ): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "create_signed_evm_signing_offer", + payload, + }); + } + + async createUsernameAttestation( + payload: UsernameAttestation, + ): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "create_username_attestation", + payload, + }); + } + + async createWalletAttestation(payload: WalletAttestation): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "create_wallet_attestation", + payload, + }); + } + + async deleteExternalIdAttestation(payload: ActionHash): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "delete_external_id_attestation", + payload, + }); + } + + async deleteUsernameAttestation(payload: ActionHash): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "delete_username_attestation", + payload, + }); + } + + async doesAgentHaveUsername(payload: AgentPubKey): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "does_agent_have_username", + payload, + }); + } + + async executeRecipe(payload: ExecuteRecipePayload): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "execute_recipe", + payload, + }); + } + + async getAllExternalIdAhs(): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_all_external_id_ahs", + payload: null, + }); + } + + async getAllUsernameAttestations(): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_all_username_attestations", + payload: null, + }); + } + + async getAttestationForExternalId(payload: string): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_attestation_for_external_id", + payload, + }); + } + + async getAuthority(): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_authority", + payload: null, + }); + } + + async getEvmWalletBindingMessage(payload: Uint8Array): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_evm_wallet_binding_message", + payload, + }); + } + + async getExternalIdAttestation(payload: ActionHash): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_external_id_attestation", + payload, + }); + } + + async getExternalIdAttestationsForAgent( + payload: AgentPubKey, + ): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_external_id_attestations_for_agent", + payload, + }); + } + + async getLatestEvmSigningOfferAhForName( + payload: string, + ): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_latest_evm_signing_offer_ah_for_name", + payload, + }); + } + + async getMetadata(payload: AgentPubKey): Promise<{ [key: string]: string }> { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_metadata", + payload, + }); + } + + async getMetadataItemValue( + payload: GetMetadataItemValuePayload, + ): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_metadata_item_value", + payload, + }); + } + + async getOracleDocumentLinkAhsForName( + payload: string, + ): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_oracle_document_link_ahs_for_name", + payload, + }); + } + + async getRelatedOracleDocumentNames(payload: string): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_related_oracle_document_names", + payload, + }); + } + + async getRelationLinkAhs(payload: string): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_relation_link_ahs", + payload, + }); + } + + async getSigningOfferAhsForEvmAddress( + payload: Uint8Array, + ): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_signing_offer_ahs_for_evm_address", + payload, + }); + } + + async getSolanaWalletBindingMessage(payload: Uint8Array): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_solana_wallet_binding_message", + payload, + }); + } + + async getUsernameAttestation(payload: ActionHash): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_username_attestation", + payload, + }); + } + + async getUsernameAttestationForAgent( + payload: AgentPubKey, + ): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_username_attestation_for_agent", + payload, + }); + } + + async getWalletAttestation(payload: ActionHash): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_wallet_attestation", + payload, + }); + } + + async getWalletAttestationsForAgent(payload: AgentPubKey): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "get_wallet_attestations_for_agent", + payload, + }); + } + + async ingestEvmSignatureOverRecipeExecutionRequest( + payload: EvmSignatureOverRecipeExecutionRequest, + ): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "ingest_evm_signature_over_recipe_execution_request", + payload, + }); + } + + async ingestExternalIdAttestationRequest( + payload: IngestExternalIdAttestationRequestPayload, + ): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "ingest_external_id_attestation_request", + payload, + }); + } + + async ingestSignedUsername(payload: SignedUsername): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "ingest_signed_username", + payload, + }); + } + + async rejectEvmSignatureOverRecipeExecutionRequest( + payload: RejectEvmSignatureOverRecipeExecutionRequestPayload, + ): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "reject_evm_signature_over_recipe_execution_request", + payload, + }); + } + + async rejectExternalIdRequest( + payload: RejectExternalIdRequestPayload, + ): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "reject_external_id_request", + payload, + }); + } + + async relateOracleDocument(payload: DocumentRelationTag): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "relate_oracle_document", + payload, + }); + } + + async resolveEvmSignatureOverRecipeExecutionRequest( + payload: ResolveEvmSignatureOverRecipeExecutionRequestPayload, + ): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "resolve_evm_signature_over_recipe_execution_request", + payload, + }); + } + + async sendExternalIdAttestationRequest( + payload: SendExternalIdAttestationRequestPayload, + ): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "send_external_id_attestation_request", + payload, + }); + } + + async sendRequestForEvmSignatureOverRecipeExecution( + payload: EvmSignatureOverRecipeExecutionRequest, + ): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "send_request_for_evm_signature_over_recipe_execution", + payload, + }); + } + + async signUsernameToAttest(payload: string): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "sign_username_to_attest", + payload, + }); + } + + async updateMetadataItem(payload: UpdateMetadataItemPayload): Promise { + return this.client.callZome({ + role_name: this.roleName, + zome_name: this.zomeName, + fn_name: "update_metadata_item", + payload, + }); + } +} diff --git a/packages/types/src/zome-functions/index.ts b/packages/types/src/zome-functions/index.ts new file mode 100644 index 0000000..b59902c --- /dev/null +++ b/packages/types/src/zome-functions/index.ts @@ -0,0 +1,4 @@ +export * from "./PingCoordinator"; +export * from "./RecordsCoordinator"; +export * from "./SignerCoordinator"; +export * from "./UsernameRegistryCoordinator"; From a6400870fd8799b57a176f26fe0b5faaa9dc2dcd Mon Sep 17 00:00:00 2001 From: 8e8b2c <8e8b2c@proton.me> Date: Tue, 6 Aug 2024 17:26:13 +0100 Subject: [PATCH 2/3] fix: stablise import order; correct zome name; hook up generated clients --- .../evm-bytes-signer-client.ts | 75 ++++------- .../src/evm-bytes-signer/offer-creator.ts | 43 +++--- .../external-id-attestor-client.ts | 45 ++----- packages/authority/src/query/index.ts | 34 ++--- .../evm-bytes-signature-requestor-client.ts | 29 +++-- ...xternal-id-attestation-requestor-client.ts | 19 ++- packages/client/src/holoom-client.ts | 123 ++++++------------ packages/e2e/src/main.ts | 10 +- .../types/scripts/extract-fn-bindings.mjs | 6 +- .../src/zome-functions/PingCoordinator.ts | 2 +- .../src/zome-functions/RecordsCoordinator.ts | 4 +- .../src/zome-functions/SignerCoordinator.ts | 2 +- .../UsernameRegistryCoordinator.ts | 26 ++-- 13 files changed, 164 insertions(+), 254 deletions(-) diff --git a/packages/authority/src/evm-bytes-signer/evm-bytes-signer-client.ts b/packages/authority/src/evm-bytes-signer/evm-bytes-signer-client.ts index c12a22b..ed052f5 100644 --- a/packages/authority/src/evm-bytes-signer/evm-bytes-signer-client.ts +++ b/packages/authority/src/evm-bytes-signer/evm-bytes-signer-client.ts @@ -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 extends { type: K } ? T : never; @@ -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 { - 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 { - 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) { @@ -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), + } + ); } } } diff --git a/packages/authority/src/evm-bytes-signer/offer-creator.ts b/packages/authority/src/evm-bytes-signer/offer-creator.ts index dd990f7..ca6df50 100644 --- a/packages/authority/src/evm-bytes-signer/offer-creator.ts +++ b/packages/authority/src/evm-bytes-signer/offer-creator.ts @@ -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, @@ -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; @@ -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)); } diff --git a/packages/authority/src/external-id-attestor/external-id-attestor-client.ts b/packages/authority/src/external-id-attestor/external-id-attestor-client.ts index b4576dd..db4e566 100644 --- a/packages/authority/src/external-id-attestor/external-id-attestor-client.ts +++ b/packages/authority/src/external-id-attestor/external-id-attestor-client.ts @@ -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 extends { type: K } ? T : never; @@ -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 { - 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 { - 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) { @@ -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), diff --git a/packages/authority/src/query/index.ts b/packages/authority/src/query/index.ts index 3b5ce98..078c0f1 100644 --- a/packages/authority/src/query/index.ts +++ b/packages/authority/src/query/index.ts @@ -5,7 +5,6 @@ import { AppWebsocket, decodeHashFromBase64, encodeHashToBase64, - Record, } from "@holochain/client"; import express, { Request, Response } from "express"; import { @@ -14,7 +13,7 @@ import { UsernameRegistryWalletsResponse, } from "./types"; import { decodeAppEntry } from "./utils"; -import { WalletAttestation } from "@holoom/types"; +import { UsernameRegistryCoordinator, WalletAttestation } from "@holoom/types"; import { bytesToHex, checksumAddress, Hex } from "viem"; import bs58 from "bs58"; @@ -45,6 +44,9 @@ export async function runQueryFromEnv() { wsClientOptions: { origin: "holoom" }, token: issuedToken.token, }); + const usernameRegistryCoordinator = new UsernameRegistryCoordinator( + appAgentClient + ); console.log("EvmBytesSignerClient listening for incoming requests"); @@ -55,12 +57,8 @@ export async function runQueryFromEnv() { console.log("GET: /username_registry"); try { - const records: Record[] = await appAgentClient.callZome({ - role_name: "holoom", - zome_name: "username_registry", - fn_name: "get_all_username_attestations", - payload: null, - }); + const records = + await usernameRegistryCoordinator.getAllUsernameAttestations(); const response: UsernameRegistryResponse = { success: true, items: records.map((record) => { @@ -89,12 +87,10 @@ export async function runQueryFromEnv() { console.log(`GET: /username_registry/${agentPubkeyB64}/wallets`); try { - const records: Record[] = await appAgentClient.callZome({ - role_name: "holoom", - zome_name: "username_registry", - fn_name: "get_wallet_attestations_for_agent", - payload: decodeHashFromBase64(agentPubkeyB64), - }); + const records = + await usernameRegistryCoordinator.getWalletAttestationsForAgent( + decodeHashFromBase64(agentPubkeyB64) + ); const attestations = records.map(decodeAppEntry); @@ -140,13 +136,9 @@ export async function runQueryFromEnv() { console.log(`GET: /username_registry/${agentPubkeyB64}/metadata`); try { - const metadata: { [key: string]: string } = - await appAgentClient.callZome({ - role_name: "holoom", - zome_name: "username_registry", - fn_name: "get_metadata", - payload: decodeHashFromBase64(agentPubkeyB64), - }); + const metadata = await usernameRegistryCoordinator.getMetadata( + decodeHashFromBase64(agentPubkeyB64) + ); const response: UsernameRegistryMetadataResponse = { success: true, diff --git a/packages/client/src/evm-bytes-signature-requestor-client.ts b/packages/client/src/evm-bytes-signature-requestor-client.ts index 6bd2fb3..5b68be0 100644 --- a/packages/client/src/evm-bytes-signature-requestor-client.ts +++ b/packages/client/src/evm-bytes-signature-requestor-client.ts @@ -1,9 +1,10 @@ -import type { ActionHash, AppWebsocket, AppSignal } from "@holochain/client"; +import type { ActionHash, AppSignal, AppClient } from "@holochain/client"; import { v4 as uuidV4 } from "uuid"; import { EvmSignatureOverRecipeExecutionRequest, LocalHoloomSignal, SignedEvmU256Array, + UsernameRegistryCoordinator, } from "@holoom/types"; import { PickByType } from "./types"; @@ -29,8 +30,12 @@ class RequestResolver { } export class EvmBytesSignatureRequestorClient { - constructor(readonly appAgent: AppWebsocket) { - appAgent.on("signal", (signal) => this.handleAppSignal(signal)); + usernameRegistryCoordinator: UsernameRegistryCoordinator; + constructor(readonly appClient: AppClient) { + this.usernameRegistryCoordinator = new UsernameRegistryCoordinator( + appClient + ); + appClient.on("signal", (signal) => this.handleAppSignal(signal)); } resolvers: { [requestId: string]: RequestResolver } = {}; @@ -43,17 +48,13 @@ export class EvmBytesSignatureRequestorClient { const resolver = new RequestResolver(); this.resolvers[requestId] = resolver; - const payload: EvmSignatureOverRecipeExecutionRequest = { - request_id: requestId, - recipe_execution_ah: arg.recipeExecutionAh, - signing_offer_ah: arg.signingOfferAh, - }; - await this.appAgent.callZome({ - role_name: "holoom", - zome_name: "username_registry", - fn_name: "send_request_for_evm_signature_over_recipe_execution", - payload, - }); + await this.usernameRegistryCoordinator.sendRequestForEvmSignatureOverRecipeExecution( + { + request_id: requestId, + recipe_execution_ah: arg.recipeExecutionAh, + signing_offer_ah: arg.signingOfferAh, + } + ); const signedEvmU256Array = await resolver.until(); return signedEvmU256Array; diff --git a/packages/client/src/external-id-attestation-requestor-client.ts b/packages/client/src/external-id-attestation-requestor-client.ts index 9441475..d327623 100644 --- a/packages/client/src/external-id-attestation-requestor-client.ts +++ b/packages/client/src/external-id-attestation-requestor-client.ts @@ -1,8 +1,9 @@ -import type { AppWebsocket, AppSignal, Record } from "@holochain/client"; +import type { AppSignal, Record, AppClient } from "@holochain/client"; import { v4 as uuidV4 } from "uuid"; import { LocalHoloomSignal, SendExternalIdAttestationRequestPayload, + UsernameRegistryCoordinator, } from "@holoom/types"; import { PickByType } from "./types"; @@ -30,8 +31,12 @@ class RequestResolver { */ export class ExternalIdAttestationRequestorClient { - constructor(readonly appAgent: AppWebsocket) { - appAgent.on("signal", (signal) => this.handleAppSignal(signal)); + usernameRegistryCoordinator: UsernameRegistryCoordinator; + constructor(readonly appClient: AppClient) { + this.usernameRegistryCoordinator = new UsernameRegistryCoordinator( + appClient + ); + appClient.on("signal", (signal) => this.handleAppSignal(signal)); } resolvers: { [requestId: string]: RequestResolver } = {}; @@ -58,16 +63,10 @@ export class ExternalIdAttestationRequestorClient { const resolver = new RequestResolver(); this.resolvers[requestId] = resolver; - const payload: SendExternalIdAttestationRequestPayload = { + await this.usernameRegistryCoordinator.sendExternalIdAttestationRequest({ request_id: requestId, code_verifier: codeVerifier, code, - }; - await this.appAgent.callZome({ - role_name: "holoom", - zome_name: "username_registry", - fn_name: "send_external_id_attestation_request", - payload, }); const attestation = await resolver.until(); diff --git a/packages/client/src/holoom-client.ts b/packages/client/src/holoom-client.ts index 558bd08..2d2a48f 100644 --- a/packages/client/src/holoom-client.ts +++ b/packages/client/src/holoom-client.ts @@ -1,11 +1,12 @@ -import type { AppWebsocket, Record } from "@holochain/client"; +import type { AgentPubKey, AppClient, Record } from "@holochain/client"; import type { PublicKey as SolanaPublicKey } from "@solana/web3.js"; import { - ChainWalletSignature, ExecuteRecipePayload, + PingCoordinator, Recipe, RecipeExecution, UsernameAttestation, + UsernameRegistryCoordinator, WalletAttestation, } from "@holoom/types"; import { BoundWallet } from "./types"; @@ -26,16 +27,15 @@ import bs58 from "bs58"; * - Binding Solana and Ethereum wallets to the user's AgentPubKey */ export class HoloomClient { - constructor(readonly appAgent: AppWebsocket) {} - - /** @ignore */ - private async ping(): Promise { - await this.appAgent.callZome({ - role_name: "holoom", - zome_name: "ping", - fn_name: "ping", - payload: null, - }); + private usernameRegistryCoordinator: UsernameRegistryCoordinator; + private pingCoordinator: PingCoordinator; + private myPubKey: AgentPubKey; + constructor(appClient: AppClient) { + this.myPubKey = appClient.myPubKey; + this.usernameRegistryCoordinator = new UsernameRegistryCoordinator( + appClient + ); + this.pingCoordinator = new PingCoordinator(appClient); } /** @@ -46,7 +46,7 @@ export class HoloomClient { const start = Date.now(); while (Date.now() - start < timeout) { try { - await this.ping(); + await this.pingCoordinator.ping(); return; } catch { await new Promise((r) => setTimeout(r, interval)); @@ -64,12 +64,10 @@ export class HoloomClient { * hosts on the holo network. */ async getUsername(): Promise { - const record = await this.appAgent.callZome({ - role_name: "holoom", - zome_name: "username_registry", - fn_name: "get_username_attestation_for_agent", - payload: this.appAgent.myPubKey, - }); + const record = + await this.usernameRegistryCoordinator.getUsernameAttestationForAgent( + this.myPubKey + ); if (!record) { return null; } @@ -85,12 +83,7 @@ export class HoloomClient { * agent, which checks the signature and attests the username's uniqueness. */ async registerUsername(username: string) { - await this.appAgent.callZome({ - role_name: "holoom", - zome_name: "username_registry", - fn_name: "sign_username_to_attest", - payload: username, - }); + await this.usernameRegistryCoordinator.signUsernameToAttest(username); } /** @@ -101,11 +94,10 @@ export class HoloomClient { * on the agent in question. */ async setMetadata(name: string, value: string) { - await this.appAgent.callZome({ - role_name: "holoom", - zome_name: "username_registry", - fn_name: "update_metadata_item", - payload: { agent_pubkey: this.appAgent.myPubKey, name, value }, + await this.usernameRegistryCoordinator.updateMetadataItem({ + agent_pubkey: this.myPubKey, + name, + value, }); } @@ -117,12 +109,10 @@ export class HoloomClient { * conductor hasn't received gossip of the latest information - this is * likely to happen when switching hosts on the holo network. */ - async getMetadata(name: string): Promise { - const value = await this.appAgent.callZome({ - role_name: "holoom", - zome_name: "username_registry", - fn_name: "get_metadata_item_value", - payload: { agent_pubkey: this.appAgent.myPubKey, name }, + async getMetadata(name: string) { + const value = await this.usernameRegistryCoordinator.getMetadataItemValue({ + agent_pubkey: this.myPubKey, + name, }); if (!value) return null; return value; @@ -137,12 +127,10 @@ export class HoloomClient { * before first submitting their binding signature. */ async getEvmWalletBindingMessage(evmAddress: Hex) { - const message: string = await this.appAgent.callZome({ - role_name: "holoom", - zome_name: "username_registry", - fn_name: "get_evm_wallet_binding_message", - payload: hexToBytes(evmAddress), - }); + const message = + await this.usernameRegistryCoordinator.getEvmWalletBindingMessage( + hexToBytes(evmAddress) + ); return message; } @@ -154,17 +142,11 @@ export class HoloomClient { * `getEvmWalletBindingMessage`. */ async submitEvmWalletBinding(evmAddress: Hex, evmSignature: Hex) { - const chain_wallet_signature: ChainWalletSignature = { + await this.usernameRegistryCoordinator.attestWalletSignature({ Evm: { evm_address: hexToBytes(evmAddress), evm_signature: formatEvmSignature(evmSignature), }, - }; - await this.appAgent.callZome({ - role_name: "holoom", - zome_name: "username_registry", - fn_name: "attest_wallet_signature", - payload: chain_wallet_signature, }); } @@ -177,12 +159,10 @@ export class HoloomClient { * before first submitting their binding signature. */ async getSolanaWalletBindingMessage(solanaPublicKey: SolanaPublicKey) { - const message: string = await this.appAgent.callZome({ - role_name: "holoom", - zome_name: "username_registry", - fn_name: "get_solana_wallet_binding_message", - payload: solanaPublicKey.toBytes(), - }); + const message = + await this.usernameRegistryCoordinator.getSolanaWalletBindingMessage( + solanaPublicKey.toBytes() + ); return message; } @@ -197,17 +177,11 @@ export class HoloomClient { solanaPublicKey: SolanaPublicKey, solanaSignature: Uint8Array ) { - const chain_wallet_signature: ChainWalletSignature = { + await this.usernameRegistryCoordinator.attestWalletSignature({ Solana: { solana_address: solanaPublicKey.toBytes(), solana_signature: Array.from(solanaSignature), }, - }; - await this.appAgent.callZome({ - role_name: "holoom", - zome_name: "username_registry", - fn_name: "attest_wallet_signature", - payload: chain_wallet_signature, }); } @@ -219,12 +193,10 @@ export class HoloomClient { * happen when switching hosts on the holo network. */ async getBoundWallets(): Promise { - const records: Record[] = await this.appAgent.callZome({ - role_name: "holoom", - zome_name: "username_registry", - fn_name: "get_wallet_attestations_for_agent", - payload: this.appAgent.myPubKey, - }); + const records = + await this.usernameRegistryCoordinator.getWalletAttestationsForAgent( + this.myPubKey + ); return records.map((record) => { const entry = decodeAppEntry(record); @@ -241,22 +213,13 @@ export class HoloomClient { } async createRecipe(recipe: Recipe): Promise { - const record: Record = await this.appAgent.callZome({ - role_name: "holoom", - zome_name: "username_registry", - fn_name: "create_recipe", - payload: recipe, - }); + const record = await this.usernameRegistryCoordinator.createRecipe(recipe); return record; } async executeRecipe(payload: ExecuteRecipePayload): Promise { - const record: Record = await this.appAgent.callZome({ - role_name: "holoom", - zome_name: "username_registry", - fn_name: "create_recipe", - payload, - }); + const record = + await this.usernameRegistryCoordinator.executeRecipe(payload); return decodeAppEntry(record).output; } } diff --git a/packages/e2e/src/main.ts b/packages/e2e/src/main.ts index 4f2661e..7845d9e 100644 --- a/packages/e2e/src/main.ts +++ b/packages/e2e/src/main.ts @@ -36,7 +36,7 @@ async function createClients() { // Hand off the puppeteer to fill out iframe await untilSignedIn(holo); global.agentPubKeyB64 = encodeHashToBase64(holo.myPubKey); - const holoom = new HoloomClient(holo as unknown as AppWebsocket); + const holoom = new HoloomClient(holo); await holoom.untilReady(); @@ -47,12 +47,8 @@ async function createClients() { clientId: "mock-client-id", clientSecret: "mock-client-secret", }); - const externalIdRequestor = new ExternalIdAttestationRequestorClient( - holo as unknown as AppWebsocket - ); - const evmSignatureRequestor = new EvmBytesSignatureRequestorClient( - holo as unknown as AppWebsocket - ); + const externalIdRequestor = new ExternalIdAttestationRequestorClient(holo); + const evmSignatureRequestor = new EvmBytesSignatureRequestorClient(holo); if (window.location.pathname.includes("/auth/callback")) { const { code, codeVerifier } = faceitAuthFlow.getCodes(); global.externalIdRequestProm = externalIdRequestor diff --git a/packages/types/scripts/extract-fn-bindings.mjs b/packages/types/scripts/extract-fn-bindings.mjs index 02fd849..e82d6f3 100644 --- a/packages/types/scripts/extract-fn-bindings.mjs +++ b/packages/types/scripts/extract-fn-bindings.mjs @@ -97,9 +97,9 @@ async function extractFnBindingsForCrate(name, typesTransform) { splitDeps[location].push(name); } - let classFile = `import {${splitDeps.holochain.join(", ")}} from '@holochain/client';\n`; + let classFile = `import {${splitDeps.holochain.sort().join(", ")}} from '@holochain/client';\n`; if (splitDeps.holoom.length) { - classFile += `import {${splitDeps.holoom.join(", ")}} from '../types';\n`; + classFile += `import {${splitDeps.holoom.sort().join(", ")}} from '../types';\n`; } const className = snakeToUpperCamel(name); classFile += ` @@ -107,7 +107,7 @@ async function extractFnBindingsForCrate(name, typesTransform) { constructor( private readonly client: AppClient, private readonly roleName = 'holoom', - private readonly zomeName = '${name}', + private readonly zomeName = '${name.replace("_coordinator", "")}', ) {} ${methodStrs.join("\n\n")} diff --git a/packages/types/src/zome-functions/PingCoordinator.ts b/packages/types/src/zome-functions/PingCoordinator.ts index dbcdd9c..af9c334 100644 --- a/packages/types/src/zome-functions/PingCoordinator.ts +++ b/packages/types/src/zome-functions/PingCoordinator.ts @@ -4,7 +4,7 @@ export class PingCoordinator { constructor( private readonly client: AppClient, private readonly roleName = "holoom", - private readonly zomeName = "ping_coordinator", + private readonly zomeName = "ping", ) {} async ping(): Promise { diff --git a/packages/types/src/zome-functions/RecordsCoordinator.ts b/packages/types/src/zome-functions/RecordsCoordinator.ts index dd41d86..e8f1f02 100644 --- a/packages/types/src/zome-functions/RecordsCoordinator.ts +++ b/packages/types/src/zome-functions/RecordsCoordinator.ts @@ -1,10 +1,10 @@ -import { AppClient, ActionHash, Record } from "@holochain/client"; +import { ActionHash, AppClient, Record } from "@holochain/client"; export class RecordsCoordinator { constructor( private readonly client: AppClient, private readonly roleName = "holoom", - private readonly zomeName = "records_coordinator", + private readonly zomeName = "records", ) {} async getRecord(payload: ActionHash): Promise { diff --git a/packages/types/src/zome-functions/SignerCoordinator.ts b/packages/types/src/zome-functions/SignerCoordinator.ts index 9c53bc6..8427917 100644 --- a/packages/types/src/zome-functions/SignerCoordinator.ts +++ b/packages/types/src/zome-functions/SignerCoordinator.ts @@ -5,7 +5,7 @@ export class SignerCoordinator { constructor( private readonly client: AppClient, private readonly roleName = "holoom", - private readonly zomeName = "signer_coordinator", + private readonly zomeName = "signer", ) {} async signMessage(payload: SignableBytes): Promise { diff --git a/packages/types/src/zome-functions/UsernameRegistryCoordinator.ts b/packages/types/src/zome-functions/UsernameRegistryCoordinator.ts index f8249b0..63d06c1 100644 --- a/packages/types/src/zome-functions/UsernameRegistryCoordinator.ts +++ b/packages/types/src/zome-functions/UsernameRegistryCoordinator.ts @@ -1,32 +1,32 @@ -import { AppClient, ActionHash, Record, AgentPubKey } from "@holochain/client"; +import { ActionHash, AgentPubKey, AppClient, Record } from "@holochain/client"; import { - RejectEvmSignatureOverRecipeExecutionRequestPayload, - ResolveEvmSignatureOverRecipeExecutionRequestPayload, - EvmSignatureOverRecipeExecutionRequest, + ChainWalletSignature, + ConfirmExternalIdRequestPayload, CreateEvmSigningOfferPayload, + DocumentRelationTag, + EvmSignatureOverRecipeExecutionRequest, + ExecuteRecipePayload, ExternalIdAttestation, - RejectExternalIdRequestPayload, - ConfirmExternalIdRequestPayload, + GetMetadataItemValuePayload, IngestExternalIdAttestationRequestPayload, - SendExternalIdAttestationRequestPayload, - DocumentRelationTag, OracleDocument, Recipe, - ExecuteRecipePayload, RecipeExecution, + RejectEvmSignatureOverRecipeExecutionRequestPayload, + RejectExternalIdRequestPayload, + ResolveEvmSignatureOverRecipeExecutionRequestPayload, + SendExternalIdAttestationRequestPayload, SignedUsername, + UpdateMetadataItemPayload, UsernameAttestation, WalletAttestation, - ChainWalletSignature, - GetMetadataItemValuePayload, - UpdateMetadataItemPayload, } from "../types"; export class UsernameRegistryCoordinator { constructor( private readonly client: AppClient, private readonly roleName = "holoom", - private readonly zomeName = "username_registry_coordinator", + private readonly zomeName = "username_registry", ) {} async attestWalletSignature(payload: ChainWalletSignature): Promise { From fe84e2b698edb3ac97e7359dd1cedd8ac6d702bf Mon Sep 17 00:00:00 2001 From: 8e8b2c <8e8b2c@proton.me> Date: Tue, 6 Aug 2024 17:27:20 +0100 Subject: [PATCH 3/3] fix: stabilise signing-offer test --- packages/e2e/tests/signing-offer.test.js | 33 +++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/e2e/tests/signing-offer.test.js b/packages/e2e/tests/signing-offer.test.js index a7246e4..5519b06 100644 --- a/packages/e2e/tests/signing-offer.test.js +++ b/packages/e2e/tests/signing-offer.test.js @@ -91,18 +91,27 @@ describe("signing-offer", () => { } debug("Polled until EvmSigningOffer gossiped"); - const ahsNumArrs = await page.evaluate( - async (evmAddressNumArr) => { - const ahs = await clients.holo.callZome({ - role_name: "holoom", - zome_name: "username_registry", - fn_name: "get_signing_offer_ahs_for_evm_address", - payload: new Uint8Array(evmAddressNumArr), - }); - return ahs.map((ah) => Array.from(ah)); - }, - Array.from(hexToBytes("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266")) - ); + let ahsNumArrs; + while (true) { + ahsNumArrs = await page.evaluate( + async (evmAddressNumArr) => { + const ahs = await clients.holo.callZome({ + role_name: "holoom", + zome_name: "username_registry", + fn_name: "get_signing_offer_ahs_for_evm_address", + payload: new Uint8Array(evmAddressNumArr), + }); + return ahs.map((ah) => Array.from(ah)); + }, + Array.from(hexToBytes("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266")) + ); + if ((signingOfferActionHashNumArray?.length ?? 0) > 0) { + break; + } else { + await new Promise((r) => setTimeout(r, 500)); + } + } + expect(ahsNumArrs).toEqual([signingOfferActionHashNumArray]); debug("Check offer linked against evm address");