Repository: nemi-fi/wallet-sdk
Pull request #9: feat: add setPublicAuthwit
Author: login: porco-rosso-j
Created: 2025-04-28T11:25:06Z | Merged: 2025-04-28T22:07:57Z



Diff:
diff --git a/package.json b/package.json
index 2b25ce0..ed78b99 100644
--- a/package.json
+++ b/package.json
@@ -56,7 +56,7 @@
     "@aztec/entrypoints": "0.85.0-alpha-testnet.2",
     "@aztec/protocol-contracts": "0.85.0-alpha-testnet.2",
     "@aztec/stdlib": "0.85.0-alpha-testnet.2",
-    "@obsidion/bridge": "0.5.0",
+    "@obsidion/bridge": "0.6.0",
     "@walletconnect/modal-sign-html": "^2.6.2",
     "@walletconnect/utils": "^2.11.2",
     "lodash-es": "^4.17.21",
diff --git a/src/exports/eip1193.ts b/src/exports/eip1193.ts
index 0f452af..d5ce798 100644
--- a/src/exports/eip1193.ts
+++ b/src/exports/eip1193.ts
@@ -1,13 +1,17 @@
 import {
   AztecAddress,
+  computeAuthWitMessageHash,
   Fr,
+  FunctionType,
   SentTx,
   TxHash,
   type AztecNode,
   type Capsule,
   type ContractArtifact,
   type FeePaymentMethod,
+  type FunctionAbi,
   type FunctionCall,
+  type IntentInnerHash,
   type PXE,
   type Wallet,
 } from "@aztec/aztec.js";
@@ -16,7 +20,8 @@ import {
   LiteralArtifactStrategy,
   type IArtifactStrategy,
 } from "../artifacts.js";
-import type { Contract, IntentAction } from "../contract.js";
+import type { Contract, IntentAction, SendOptions } from "../contract.js";
+import { ContractFunctionInteraction } from "../contract.js";
 import { createEip1193ProviderFromAccounts } from "../createEip1193ProviderFromAccounts.js";
 import {
   encodeCapsules,
@@ -24,6 +29,8 @@ import {
   encodeRegisterContracts,
 } from "../serde.js";
 import type { Eip1193Provider, TypedEip1193Provider } from "../types.js";
+import type { ABIParameterVisibility } from "@aztec/stdlib/abi";
+import { getCanonicalAuthRegistry } from "@aztec/protocol-contracts/auth-registry";
 
 export { BatchCall, Contract } from "../contract.js";
 
@@ -125,6 +132,58 @@ export class Eip1193Account {
       artifactStrategy,
     );
   }
+
+  public async setPublicAuthWit(
+    messageHashOrIntent: Fr | Uint8Array | IntentInnerHash | IntentAction,
+    authorized: boolean,
+    options?: SendOptions,
+  ): Promise<ContractFunctionInteraction> {
+    let messageHash: Fr;
+    if (messageHashOrIntent instanceof Uint8Array) {
+      messageHash = Fr.fromBuffer(Buffer.from(messageHashOrIntent));
+    } else if (messageHashOrIntent instanceof Fr) {
+      messageHash = messageHashOrIntent;
+    } else {
+      const chainId = new Fr(await this.aztecNode.getChainId());
+      const version = new Fr(await this.aztecNode.getVersion());
+      messageHash = await computeAuthWitMessageHash(messageHashOrIntent, {
+        chainId,
+        version,
+      });
+    }
+
+    return new ContractFunctionInteraction(
+      await getCanonicalAuthRegistry(),
+      this,
+      this.getSetAuthorizedAbi(),
+      [messageHash, authorized],
+      options,
+    );
+  }
+
+  private getSetAuthorizedAbi(): FunctionAbi {
+    return {
+      name: "set_authorized",
+      isInitializer: false,
+      functionType: FunctionType.PUBLIC,
+      isInternal: true,
+      isStatic: false,
+      parameters: [
+        {
+          name: "message_hash",
+          type: { kind: "field" },
+          visibility: "private" as ABIParameterVisibility,
+        },
+        {
+          name: "authorize",
+          type: { kind: "boolean" },
+          visibility: "private" as ABIParameterVisibility,
+        },
+      ],
+      returnTypes: [],
+      errorTypes: {},
+    };
+  }
 }
 
 export type TransactionRequest = {
diff --git a/src/types.ts b/src/types.ts
index afc3be9..5709a8a 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -161,6 +161,7 @@ export interface Account
     | "aztecNode"
     | "sendTransaction"
     | "simulateTransaction"
+    | "setPublicAuthWit"
   > {}
 /**
  * @deprecated use {@link Account} instead


Reviews:
user: login: olehmisar
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-04-28T11:29:43Z

Review comments:
diff_hunk: @@ -125,6 +132,58 @@ export class Eip1193Account {
       artifactStrategy,
     );
   }
+
+  public async setPublicAuthWit(
+    messageHashOrIntent: Fr | Buffer | IntentInnerHash | IntentAction,
+    authorized: boolean,
+    options?: SendOptions,
+  ): Promise<ContractFunctionInteraction> {
+    let messageHash: Fr;
+    if (Buffer.isBuffer(messageHashOrIntent)) {
+      messageHash = Fr.fromBuffer(messageHashOrIntent);
path: src/exports/eip1193.ts
user: login: olehmisar
body: ```suggestion
    if (messageHashOrIntent instanceof Uint8Array) {
      messageHash = Fr.fromBuffer(Buffer.from(messageHashOrIntent));
```
created_at: 2025-04-28T11:27:59Z
author_association: COLLABORATOR
diff_hunk: @@ -125,6 +132,58 @@ export class Eip1193Account {
       artifactStrategy,
     );
   }
+
+  public async setPublicAuthWit(
+    messageHashOrIntent: Fr | Buffer | IntentInnerHash | IntentAction,
path: src/exports/eip1193.ts
user: login: olehmisar
body: ```suggestion
    messageHashOrIntent: Fr | Uint8Array | IntentInnerHash | IntentAction,
```
created_at: 2025-04-28T11:28:25Z
author_association: COLLABORATOR

PR comments:
user: login: olehmisar
created_at: 2025-04-28T11:29:56Z
body: did you test it somehow?
author_association: COLLABORATOR
user: login: porco-rosso-j
created_at: 2025-04-28T12:33:46Z
body: Yeah but it was just adding fake authwit into AuthRegistry contract ( so i didn't do verifying part for another call ). I did it in the context of our example token app <> Obsidion. Also, for `messageHashOrIntent` param, i didn't try with types such as Fr, Buffer, `IntentInnerHash` but only `IntentAction`.

author_association: COLLABORATOR
user: login: olehmisar
created_at: 2025-04-28T13:02:16Z
body: i committed the Uint8Array patch. I will test if it passes @nemi-fi CI (just a typecheck, we are not using public authwits anywhere) and merge if everything is good.
author_association: COLLABORATOR