@idos-network/kwil-infra 1.1.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -0
- package/README.md +1 -1
- package/dist/actions/index.d.mts +1 -1
- package/dist/actions/index.mjs.map +1 -1
- package/dist/facesign/index.d.mts +1 -1
- package/dist/facesign/index.mjs +1 -1
- package/dist/{facesign-signer-ADd4EASX.d.mts → facesign-signer-BC24j1eN.d.mts} +1 -1
- package/dist/facesign-signer-BC24j1eN.d.mts.map +1 -0
- package/dist/{facesign-signer-BY9Nti9F.mjs → facesign-signer-qzCcwunk.mjs} +1 -1
- package/dist/{facesign-signer-BY9Nti9F.mjs.map → facesign-signer-qzCcwunk.mjs.map} +1 -1
- package/dist/{index-Ci6QhKJo.d.mts → index-iqkJfgWf.d.mts} +64 -65
- package/dist/index-iqkJfgWf.d.mts.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/dist/signature-verification/index.d.mts +1 -2
- package/dist/signature-verification/index.d.mts.map +1 -1
- package/dist/signature-verification/index.mjs +11 -16
- package/dist/signature-verification/index.mjs.map +1 -1
- package/dist/xrp/utils.d.mts +35 -37
- package/dist/xrp/utils.d.mts.map +1 -1
- package/dist/xrp/utils.mjs.map +1 -1
- package/dist/xrpl-credentials/index.d.mts +156 -146
- package/dist/xrpl-credentials/index.d.mts.map +1 -1
- package/dist/xrpl-credentials/index.mjs.map +1 -1
- package/package.json +18 -13
- package/src/signature-verification/evm.test.ts +49 -0
- package/src/signature-verification/evm.ts +11 -20
- package/vitest.config.ts +4 -0
- package/.turbo/turbo-build.log +0 -47
- package/.turbo/turbo-test.log +0 -126
- package/.turbo/turbo-typecheck.log +0 -5
- package/dist/facesign-signer-ADd4EASX.d.mts.map +0 -1
- package/dist/index-Ci6QhKJo.d.mts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facesign-signer-BY9Nti9F.mjs","names":["#metadata","#enclaveUrl","#enclaveOrigin","#messageListenerInitialized","#messageListener","#hasKey","#resolveOpenEnclave","#resolveSignMessage","#rejectSignMessage","#resolveSessionProposal","#rejectSessionProposal","#resolveAddressRequest","#setupMessageListener","#ensureEnclave","#sessionProposal","#iframe","#proposalId","#showEnclave","#hideEnclave","#cancelPendingProposals","#destroyEnclave","#container","#createContainer"],"sources":["../src/facesign/facesign-signer.ts"],"sourcesContent":["// Buffer after showing the iframe before posting a message, giving the enclave time to be ready.\nconst POST_MESSAGE_DELAY_MS = 300;\n// Safety net: reject proposals if the enclave doesn't respond within this window.\nconst PROPOSAL_TIMEOUT_MS = 10 * 60 * 1000; // 10 minutes\n\nexport interface FaceSignMetadata {\n name: string;\n description: string;\n}\n\nexport interface FaceSignSignerProviderOptions {\n metadata: FaceSignMetadata;\n enclaveUrl: string;\n}\n\ninterface SessionResponse {\n address: string;\n}\n\nexport class FaceSignSignerProvider {\n #iframe: HTMLIFrameElement | null = null;\n #container: HTMLDialogElement | null = null;\n\n #resolveOpenEnclave: (() => void) | null = null;\n #resolveSignMessage: ((signature: Uint8Array) => void) | null = null;\n #rejectSignMessage: ((error: Error) => void) | null = null;\n #resolveSessionProposal: ((response: SessionResponse) => void) | null = null;\n #rejectSessionProposal: ((error: Error) => void) | null = null;\n #resolveAddressRequest: ((address: string | null) => void) | null = null;\n\n #messageListener: ((event: MessageEvent) => void) | null = null;\n #messageListenerInitialized = false;\n #proposalId = 0;\n #hasKey: boolean | null = null;\n #metadata: FaceSignMetadata;\n #enclaveUrl: string;\n #enclaveOrigin: string;\n\n signatureType = \"ed25519\";\n walletType = \"FaceSign\";\n publicAddress = \"\";\n publicKey = \"\";\n\n constructor(options: FaceSignSignerProviderOptions) {\n this.#metadata = options.metadata;\n this.#enclaveUrl = options.enclaveUrl;\n this.#enclaveOrigin = new URL(options.enclaveUrl).origin;\n }\n\n #setupMessageListener(): void {\n if (this.#messageListenerInitialized) {\n return;\n }\n\n this.#messageListener = (event: MessageEvent) => {\n if (event.origin !== this.#enclaveOrigin) return;\n\n if (event.data?.type === \"facesign_ready\") {\n this.#hasKey = !!event.data.hasKey;\n this.#resolveOpenEnclave?.();\n }\n\n if (event.data?.type === \"sign_proposal_response\") {\n const payload = event.data.data;\n if (!payload) return;\n\n if (payload.signature) {\n this.#resolveSignMessage?.(new Uint8Array(payload.signature));\n } else {\n this.#rejectSignMessage?.(new Error(\"Sign request rejected by user\"));\n }\n }\n\n if (event.data?.type === \"session_proposal_response\") {\n const payload = event.data.data;\n if (!payload) return;\n\n if (payload.approved && payload.address) {\n this.#resolveSessionProposal?.({ address: payload.address });\n } else {\n this.#rejectSessionProposal?.(new Error(\"Session request rejected by user\"));\n }\n }\n\n if (event.data?.type === \"address_response\") {\n const payload = event.data.data;\n this.#resolveAddressRequest?.(payload?.address ?? null);\n }\n };\n\n window.addEventListener(\"message\", this.#messageListener);\n this.#messageListenerInitialized = true;\n }\n\n async preload(): Promise<{ hasKey: boolean }> {\n this.#setupMessageListener();\n await this.#ensureEnclave();\n return { hasKey: this.#hasKey ?? false };\n }\n\n async init(): Promise<string> {\n this.#setupMessageListener();\n\n const sessionProposal = await this.#sessionProposal();\n\n this.publicKey = sessionProposal.address;\n this.publicAddress = sessionProposal.address;\n\n return sessionProposal.address;\n }\n\n async getAddress(): Promise<string | null> {\n this.#setupMessageListener();\n await this.#ensureEnclave();\n\n if (!this.#hasKey) return null;\n\n return new Promise<string | null>((resolve) => {\n const timer = setTimeout(() => resolve(null), PROPOSAL_TIMEOUT_MS);\n\n this.#resolveAddressRequest = (address) => {\n clearTimeout(timer);\n this.#resolveAddressRequest = null;\n if (address) {\n this.publicKey = address;\n this.publicAddress = address;\n }\n resolve(address);\n };\n\n this.#iframe?.contentWindow?.postMessage(\n { type: \"address_request\", data: { id: ++this.#proposalId } },\n this.#enclaveUrl,\n );\n });\n }\n\n get signer(): this {\n return this;\n }\n\n async signMessage(message: Uint8Array | string): Promise<Uint8Array> {\n await this.#ensureEnclave();\n this.#showEnclave();\n\n const messageToSign = typeof message === \"string\" ? new TextEncoder().encode(message) : message;\n\n try {\n return await new Promise<Uint8Array>((resolve, reject) => {\n const timer = setTimeout(() => {\n reject(new Error(\"FaceSign sign request timed out\"));\n }, PROPOSAL_TIMEOUT_MS);\n\n this.#resolveSignMessage = (sig) => {\n clearTimeout(timer);\n resolve(sig);\n };\n this.#rejectSignMessage = (err) => {\n clearTimeout(timer);\n reject(err);\n };\n\n setTimeout(() => {\n this.#iframe?.contentWindow?.postMessage(\n {\n type: \"sign_proposal\",\n data: {\n id: ++this.#proposalId,\n data: messageToSign,\n metadata: this.#metadata,\n },\n },\n this.#enclaveUrl,\n );\n }, POST_MESSAGE_DELAY_MS);\n });\n } finally {\n this.#resolveSignMessage = null;\n this.#rejectSignMessage = null;\n this.#hideEnclave();\n }\n }\n\n async #sessionProposal(): Promise<SessionResponse> {\n await this.#ensureEnclave();\n this.#showEnclave();\n\n try {\n return await new Promise<SessionResponse>((resolve, reject) => {\n const timer = setTimeout(() => {\n reject(new Error(\"FaceSign session proposal timed out\"));\n }, PROPOSAL_TIMEOUT_MS);\n\n this.#resolveSessionProposal = (res) => {\n clearTimeout(timer);\n resolve(res);\n };\n this.#rejectSessionProposal = (err) => {\n clearTimeout(timer);\n reject(err);\n };\n\n setTimeout(() => {\n this.#iframe?.contentWindow?.postMessage(\n {\n type: \"session_proposal\",\n data: {\n id: ++this.#proposalId,\n metadata: this.#metadata,\n },\n },\n this.#enclaveUrl,\n );\n }, POST_MESSAGE_DELAY_MS);\n });\n } finally {\n this.#resolveSessionProposal = null;\n this.#rejectSessionProposal = null;\n this.#hideEnclave();\n }\n }\n\n hide(): void {\n this.#cancelPendingProposals();\n this.#hideEnclave();\n }\n\n #cancelPendingProposals(): void {\n const cancelError = new Error(\"FaceSign operation cancelled\");\n\n if (this.#rejectSignMessage) {\n this.#rejectSignMessage(cancelError);\n this.#resolveSignMessage = null;\n this.#rejectSignMessage = null;\n }\n\n if (this.#rejectSessionProposal) {\n this.#rejectSessionProposal(cancelError);\n this.#resolveSessionProposal = null;\n this.#rejectSessionProposal = null;\n }\n }\n\n destroy(): void {\n this.#cancelPendingProposals();\n if (this.#messageListener) {\n window.removeEventListener(\"message\", this.#messageListener);\n this.#messageListener = null;\n }\n this.#destroyEnclave();\n }\n\n #createContainer(): HTMLDialogElement {\n const container = document.createElement(\"dialog\");\n Object.assign(container.style, {\n position: \"fixed\",\n inset: \"0\",\n width: \"100%\",\n height: \"100%\",\n maxWidth: \"100%\",\n maxHeight: \"100%\",\n margin: \"0\",\n padding: \"0\",\n border: \"none\",\n zIndex: \"99999\",\n background: \"#0a0a0a\",\n });\n document.body.appendChild(container);\n return container;\n }\n\n #ensureEnclave(): Promise<void> {\n if (this.#iframe?.contentWindow) {\n return Promise.resolve();\n }\n\n return new Promise<void>((resolve, reject) => {\n const timer = setTimeout(() => {\n reject(new Error(\"FaceSign enclave failed to load\"));\n }, PROPOSAL_TIMEOUT_MS);\n\n if (!this.#container) {\n this.#container = this.#createContainer();\n }\n\n this.#iframe = document.createElement(\"iframe\");\n this.#iframe.src = this.#enclaveUrl;\n this.#iframe.title = \"FaceSign Enclave\";\n this.#iframe.allow = \"camera; fullscreen\";\n this.#iframe.style.cssText = \"width:100%;height:100%;border:none;\";\n\n this.#container.appendChild(this.#iframe);\n\n this.#resolveOpenEnclave = () => {\n console.log(\"resolveOpenEnclave\");\n clearTimeout(timer);\n resolve();\n };\n });\n }\n\n #showEnclave(): void {\n const el = this.#container;\n\n if (el && !el.open) {\n el.showModal();\n }\n }\n\n #hideEnclave(): void {\n const el = this.#container;\n if (el?.open) {\n el.close();\n }\n }\n\n #destroyEnclave(): void {\n if (this.#iframe) {\n this.#iframe.remove();\n this.#iframe = null;\n }\n if (this.#container) {\n this.#container.remove();\n this.#container = null;\n }\n }\n}\n"],"mappings":";AACA,MAAM,wBAAwB;AAE9B,MAAM,sBAAsB,MAAU;AAgBtC,IAAa,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AAc,SAAS;AAClD,SAAO,OAAO,UAAU,OAAO;GAC7B,UAAU;GACV,OAAO;GACP,OAAO;GACP,QAAQ;GACR,UAAU;GACV,WAAW;GACX,QAAQ;GACR,SAAS;GACT,QAAQ;GACR,QAAQ;GACR,YAAY;GACb,CAAC;AACF,WAAS,KAAK,YAAY,UAAU;AACpC,SAAO;;CAGT,iBAAgC;AAC9B,MAAI,MAAA,QAAc,cAChB,QAAO,QAAQ,SAAS;AAG1B,SAAO,IAAI,SAAe,SAAS,WAAW;GAC5C,MAAM,QAAQ,iBAAiB;AAC7B,2BAAO,IAAI,MAAM,kCAAkC,CAAC;MACnD,oBAAoB;AAEvB,OAAI,CAAC,MAAA,UACH,OAAA,YAAkB,MAAA,iBAAuB;AAG3C,SAAA,SAAe,SAAS,cAAc,SAAS;AAC/C,SAAA,OAAa,MAAM,MAAA;AACnB,SAAA,OAAa,QAAQ;AACrB,SAAA,OAAa,QAAQ;AACrB,SAAA,OAAa,MAAM,UAAU;AAE7B,SAAA,UAAgB,YAAY,MAAA,OAAa;AAEzC,SAAA,2BAAiC;AAC/B,YAAQ,IAAI,qBAAqB;AACjC,iBAAa,MAAM;AACnB,aAAS;;IAEX;;CAGJ,eAAqB;EACnB,MAAM,KAAK,MAAA;AAEX,MAAI,MAAM,CAAC,GAAG,KACZ,IAAG,WAAW;;CAIlB,eAAqB;EACnB,MAAM,KAAK,MAAA;AACX,MAAI,IAAI,KACN,IAAG,OAAO;;CAId,kBAAwB;AACtB,MAAI,MAAA,QAAc;AAChB,SAAA,OAAa,QAAQ;AACrB,SAAA,SAAe;;AAEjB,MAAI,MAAA,WAAiB;AACnB,SAAA,UAAgB,QAAQ;AACxB,SAAA,YAAkB"}
|
|
1
|
+
{"version":3,"file":"facesign-signer-qzCcwunk.mjs","names":["#metadata","#enclaveUrl","#enclaveOrigin","#messageListenerInitialized","#messageListener","#hasKey","#resolveOpenEnclave","#resolveSignMessage","#rejectSignMessage","#resolveSessionProposal","#rejectSessionProposal","#resolveAddressRequest","#setupMessageListener","#ensureEnclave","#sessionProposal","#iframe","#proposalId","#showEnclave","#hideEnclave","#cancelPendingProposals","#destroyEnclave","#container","#createContainer"],"sources":["../src/facesign/facesign-signer.ts"],"sourcesContent":["// Buffer after showing the iframe before posting a message, giving the enclave time to be ready.\nconst POST_MESSAGE_DELAY_MS = 300;\n// Safety net: reject proposals if the enclave doesn't respond within this window.\nconst PROPOSAL_TIMEOUT_MS = 10 * 60 * 1000; // 10 minutes\n\nexport interface FaceSignMetadata {\n name: string;\n description: string;\n}\n\nexport interface FaceSignSignerProviderOptions {\n metadata: FaceSignMetadata;\n enclaveUrl: string;\n}\n\ninterface SessionResponse {\n address: string;\n}\n\nexport class FaceSignSignerProvider {\n #iframe: HTMLIFrameElement | null = null;\n #container: HTMLDialogElement | null = null;\n\n #resolveOpenEnclave: (() => void) | null = null;\n #resolveSignMessage: ((signature: Uint8Array) => void) | null = null;\n #rejectSignMessage: ((error: Error) => void) | null = null;\n #resolveSessionProposal: ((response: SessionResponse) => void) | null = null;\n #rejectSessionProposal: ((error: Error) => void) | null = null;\n #resolveAddressRequest: ((address: string | null) => void) | null = null;\n\n #messageListener: ((event: MessageEvent) => void) | null = null;\n #messageListenerInitialized = false;\n #proposalId = 0;\n #hasKey: boolean | null = null;\n #metadata: FaceSignMetadata;\n #enclaveUrl: string;\n #enclaveOrigin: string;\n\n signatureType = \"ed25519\";\n walletType = \"FaceSign\";\n publicAddress = \"\";\n publicKey = \"\";\n\n constructor(options: FaceSignSignerProviderOptions) {\n this.#metadata = options.metadata;\n this.#enclaveUrl = options.enclaveUrl;\n this.#enclaveOrigin = new URL(options.enclaveUrl).origin;\n }\n\n #setupMessageListener(): void {\n if (this.#messageListenerInitialized) {\n return;\n }\n\n this.#messageListener = (event: MessageEvent) => {\n if (event.origin !== this.#enclaveOrigin) return;\n\n if (event.data?.type === \"facesign_ready\") {\n this.#hasKey = !!event.data.hasKey;\n this.#resolveOpenEnclave?.();\n }\n\n if (event.data?.type === \"sign_proposal_response\") {\n const payload = event.data.data;\n if (!payload) return;\n\n if (payload.signature) {\n this.#resolveSignMessage?.(new Uint8Array(payload.signature));\n } else {\n this.#rejectSignMessage?.(new Error(\"Sign request rejected by user\"));\n }\n }\n\n if (event.data?.type === \"session_proposal_response\") {\n const payload = event.data.data;\n if (!payload) return;\n\n if (payload.approved && payload.address) {\n this.#resolveSessionProposal?.({ address: payload.address });\n } else {\n this.#rejectSessionProposal?.(new Error(\"Session request rejected by user\"));\n }\n }\n\n if (event.data?.type === \"address_response\") {\n const payload = event.data.data;\n this.#resolveAddressRequest?.(payload?.address ?? null);\n }\n };\n\n window.addEventListener(\"message\", this.#messageListener);\n this.#messageListenerInitialized = true;\n }\n\n async preload(): Promise<{ hasKey: boolean }> {\n this.#setupMessageListener();\n await this.#ensureEnclave();\n return { hasKey: this.#hasKey ?? false };\n }\n\n async init(): Promise<string> {\n this.#setupMessageListener();\n\n const sessionProposal = await this.#sessionProposal();\n\n this.publicKey = sessionProposal.address;\n this.publicAddress = sessionProposal.address;\n\n return sessionProposal.address;\n }\n\n async getAddress(): Promise<string | null> {\n this.#setupMessageListener();\n await this.#ensureEnclave();\n\n if (!this.#hasKey) return null;\n\n return new Promise<string | null>((resolve) => {\n const timer = setTimeout(() => resolve(null), PROPOSAL_TIMEOUT_MS);\n\n this.#resolveAddressRequest = (address) => {\n clearTimeout(timer);\n this.#resolveAddressRequest = null;\n if (address) {\n this.publicKey = address;\n this.publicAddress = address;\n }\n resolve(address);\n };\n\n this.#iframe?.contentWindow?.postMessage(\n { type: \"address_request\", data: { id: ++this.#proposalId } },\n this.#enclaveUrl,\n );\n });\n }\n\n get signer(): this {\n return this;\n }\n\n async signMessage(message: Uint8Array | string): Promise<Uint8Array> {\n await this.#ensureEnclave();\n this.#showEnclave();\n\n const messageToSign = typeof message === \"string\" ? new TextEncoder().encode(message) : message;\n\n try {\n return await new Promise<Uint8Array>((resolve, reject) => {\n const timer = setTimeout(() => {\n reject(new Error(\"FaceSign sign request timed out\"));\n }, PROPOSAL_TIMEOUT_MS);\n\n this.#resolveSignMessage = (sig) => {\n clearTimeout(timer);\n resolve(sig);\n };\n this.#rejectSignMessage = (err) => {\n clearTimeout(timer);\n reject(err);\n };\n\n setTimeout(() => {\n this.#iframe?.contentWindow?.postMessage(\n {\n type: \"sign_proposal\",\n data: {\n id: ++this.#proposalId,\n data: messageToSign,\n metadata: this.#metadata,\n },\n },\n this.#enclaveUrl,\n );\n }, POST_MESSAGE_DELAY_MS);\n });\n } finally {\n this.#resolveSignMessage = null;\n this.#rejectSignMessage = null;\n this.#hideEnclave();\n }\n }\n\n async #sessionProposal(): Promise<SessionResponse> {\n await this.#ensureEnclave();\n this.#showEnclave();\n\n try {\n return await new Promise<SessionResponse>((resolve, reject) => {\n const timer = setTimeout(() => {\n reject(new Error(\"FaceSign session proposal timed out\"));\n }, PROPOSAL_TIMEOUT_MS);\n\n this.#resolveSessionProposal = (res) => {\n clearTimeout(timer);\n resolve(res);\n };\n this.#rejectSessionProposal = (err) => {\n clearTimeout(timer);\n reject(err);\n };\n\n setTimeout(() => {\n this.#iframe?.contentWindow?.postMessage(\n {\n type: \"session_proposal\",\n data: {\n id: ++this.#proposalId,\n metadata: this.#metadata,\n },\n },\n this.#enclaveUrl,\n );\n }, POST_MESSAGE_DELAY_MS);\n });\n } finally {\n this.#resolveSessionProposal = null;\n this.#rejectSessionProposal = null;\n this.#hideEnclave();\n }\n }\n\n hide(): void {\n this.#cancelPendingProposals();\n this.#hideEnclave();\n }\n\n #cancelPendingProposals(): void {\n const cancelError = new Error(\"FaceSign operation cancelled\");\n\n if (this.#rejectSignMessage) {\n this.#rejectSignMessage(cancelError);\n this.#resolveSignMessage = null;\n this.#rejectSignMessage = null;\n }\n\n if (this.#rejectSessionProposal) {\n this.#rejectSessionProposal(cancelError);\n this.#resolveSessionProposal = null;\n this.#rejectSessionProposal = null;\n }\n }\n\n destroy(): void {\n this.#cancelPendingProposals();\n if (this.#messageListener) {\n window.removeEventListener(\"message\", this.#messageListener);\n this.#messageListener = null;\n }\n this.#destroyEnclave();\n }\n\n #createContainer(): HTMLDialogElement {\n const container = document.createElement(\"dialog\");\n Object.assign(container.style, {\n position: \"fixed\",\n inset: \"0\",\n width: \"100%\",\n height: \"100%\",\n maxWidth: \"100%\",\n maxHeight: \"100%\",\n margin: \"0\",\n padding: \"0\",\n border: \"none\",\n zIndex: \"99999\",\n background: \"#0a0a0a\",\n });\n document.body.appendChild(container);\n return container;\n }\n\n #ensureEnclave(): Promise<void> {\n if (this.#iframe?.contentWindow) {\n return Promise.resolve();\n }\n\n return new Promise<void>((resolve, reject) => {\n const timer = setTimeout(() => {\n reject(new Error(\"FaceSign enclave failed to load\"));\n }, PROPOSAL_TIMEOUT_MS);\n\n if (!this.#container) {\n this.#container = this.#createContainer();\n }\n\n this.#iframe = document.createElement(\"iframe\");\n this.#iframe.src = this.#enclaveUrl;\n this.#iframe.title = \"FaceSign Enclave\";\n this.#iframe.allow = \"camera; fullscreen\";\n this.#iframe.style.cssText = \"width:100%;height:100%;border:none;\";\n\n this.#container.appendChild(this.#iframe);\n\n this.#resolveOpenEnclave = () => {\n console.log(\"resolveOpenEnclave\");\n clearTimeout(timer);\n resolve();\n };\n });\n }\n\n #showEnclave(): void {\n const el = this.#container;\n\n if (el && !el.open) {\n el.showModal();\n }\n }\n\n #hideEnclave(): void {\n const el = this.#container;\n if (el?.open) {\n el.close();\n }\n }\n\n #destroyEnclave(): void {\n if (this.#iframe) {\n this.#iframe.remove();\n this.#iframe = null;\n }\n if (this.#container) {\n this.#container.remove();\n this.#container = null;\n }\n }\n}\n"],"mappings":";AACA,MAAM,wBAAwB;AAE9B,MAAM,sBAAsB,MAAU;AAgBtC,IAAa,yBAAb,MAAoC;CAClC,UAAoC;CACpC,aAAuC;CAEvC,sBAA2C;CAC3C,sBAAgE;CAChE,qBAAsD;CACtD,0BAAwE;CACxE,yBAA0D;CAC1D,yBAAoE;CAEpE,mBAA2D;CAC3D,8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1,4 @@
|
|
|
1
|
-
import { n as FaceSignSignerProvider } from "./facesign-signer-
|
|
1
|
+
import { n as FaceSignSignerProvider } from "./facesign-signer-BC24j1eN.mjs";
|
|
2
2
|
import { KwilSigner, KwilSigner as KwilSigner$1, NodeKwil, Utils, WebKwil } from "@idos-network/kwil-js";
|
|
3
3
|
import * as z from "zod";
|
|
4
4
|
import nacl from "tweetnacl";
|
|
@@ -8,7 +8,6 @@ import { Keypair } from "@stellar/stellar-sdk";
|
|
|
8
8
|
import { JsonRpcSigner, Wallet as Wallet$1 } from "ethers";
|
|
9
9
|
import { KeyPair } from "near-api-js";
|
|
10
10
|
import { KeyPair as KeyPair$1 } from "ripple-keypairs/src/types.ts";
|
|
11
|
-
|
|
12
11
|
//#region src/create-kwil-client.d.ts
|
|
13
12
|
type CreateKwilClientParams = {
|
|
14
13
|
chainId?: string;
|
|
@@ -19,38 +18,38 @@ type ActionName = keyof KwilActions;
|
|
|
19
18
|
type AllKwilCallAction = { [Name in ActionName]: {
|
|
20
19
|
name: Name;
|
|
21
20
|
inputs: Record<KwilActions[Name][number]["name"], any>;
|
|
22
|
-
} };
|
|
21
|
+
}; };
|
|
23
22
|
type KwilCallActionRequestParams = AllKwilCallAction[ActionName];
|
|
24
23
|
type AllKwilExecuteAction = { [Name in ActionName]: AllKwilCallAction[Name] & {
|
|
25
24
|
description: string;
|
|
26
|
-
} };
|
|
25
|
+
}; };
|
|
27
26
|
type KwilExecuteActionRequestParams = AllKwilExecuteAction[ActionName];
|
|
28
27
|
/**
|
|
29
|
-
* A client for interacting with kwil with type-safe abstractions for `call` and `execute`.
|
|
30
|
-
* Has utility methods for creating actions and setting a signer.
|
|
31
|
-
*/
|
|
28
|
+
* A client for interacting with kwil with type-safe abstractions for `call` and `execute`.
|
|
29
|
+
* Has utility methods for creating actions and setting a signer.
|
|
30
|
+
*/
|
|
32
31
|
declare class KwilActionClient {
|
|
33
32
|
#private;
|
|
34
33
|
signer?: KwilSigner;
|
|
35
34
|
readonly client: NodeKwil | WebKwil;
|
|
36
35
|
constructor(client: NodeKwil | WebKwil);
|
|
37
36
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
* Calls an action on the kwil nodes. This similar to `GET` like request.
|
|
38
|
+
*/
|
|
40
39
|
call<T = unknown>(params: KwilCallActionRequestParams, signer?: KwilSigner | undefined): Promise<T>;
|
|
41
40
|
/**
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
* Executes an action on the kwil nodes. This similar to `POST` like request.
|
|
42
|
+
*/
|
|
44
43
|
execute(params: KwilExecuteActionRequestParams, signer?: KwilSigner | undefined, synchronous?: boolean): Promise<string | undefined>;
|
|
45
44
|
setSigner(signer: KwilSigner | undefined): void;
|
|
46
45
|
}
|
|
47
46
|
/**
|
|
48
|
-
* Create a kwil client for node.js environment
|
|
49
|
-
*/
|
|
47
|
+
* Create a kwil client for node.js environment
|
|
48
|
+
*/
|
|
50
49
|
declare const createNodeKwilClient: (params: CreateKwilClientParams) => Promise<KwilActionClient>;
|
|
51
50
|
/**
|
|
52
|
-
* Create a kwil client for browser environment
|
|
53
|
-
*/
|
|
51
|
+
* Create a kwil client for browser environment
|
|
52
|
+
*/
|
|
54
53
|
declare const createWebKwilClient: (params: CreateKwilClientParams) => Promise<KwilActionClient>;
|
|
55
54
|
//#endregion
|
|
56
55
|
//#region src/create-kwil-signer.d.ts
|
|
@@ -66,11 +65,11 @@ type KwilSignerType = KeyPair | Wallet$1 | nacl.SignKeyPair | JsonRpcSigner | Ke
|
|
|
66
65
|
type SignerAddress = string;
|
|
67
66
|
type SignerPublicKey = string | undefined;
|
|
68
67
|
/**
|
|
69
|
-
* Creates a `KwilSigner` and its associated `SignerAddress`.
|
|
70
|
-
*
|
|
71
|
-
* This function is explicitly marked as being for backend use only because it doesn't reset
|
|
72
|
-
* the KGW cookie when logging out and re-logging in with a different wallet.
|
|
73
|
-
*/
|
|
68
|
+
* Creates a `KwilSigner` and its associated `SignerAddress`.
|
|
69
|
+
*
|
|
70
|
+
* This function is explicitly marked as being for backend use only because it doesn't reset
|
|
71
|
+
* the KGW cookie when logging out and re-logging in with a different wallet.
|
|
72
|
+
*/
|
|
74
73
|
declare function createServerKwilSigner(signer: KwilSignerType): Promise<[KwilSigner, SignerAddress]>;
|
|
75
74
|
declare function createClientKwilSigner(store: Store, kwilClient: KwilActionClient, wallet: Wallet$2): Promise<[KwilSigner, SignerAddress, SignerPublicKey, WalletType]>;
|
|
76
75
|
//#endregion
|
|
@@ -200,9 +199,9 @@ declare const UpsertCredentialAsInserterInputSchema: z.ZodObject<{
|
|
|
200
199
|
}>;
|
|
201
200
|
type UpsertCredentialAsInserterInput = z.infer<typeof UpsertCredentialAsInserterInputSchema>;
|
|
202
201
|
/**
|
|
203
|
-
* CREDENTIAL ACTIONS
|
|
204
|
-
* throw an error if not authorized
|
|
205
|
-
*/
|
|
202
|
+
* CREDENTIAL ACTIONS
|
|
203
|
+
* throw an error if not authorized
|
|
204
|
+
*/
|
|
206
205
|
declare function upsertCredentialAsInserter(kwilClient: KwilActionClient, params: UpsertCredentialAsInserterInput): Promise<void>;
|
|
207
206
|
declare const AddCredentialInputSchema: z.ZodObject<{
|
|
208
207
|
id: z.ZodUUID;
|
|
@@ -252,10 +251,10 @@ declare const EditCredentialInputSchema: z.ZodObject<{
|
|
|
252
251
|
}>;
|
|
253
252
|
type EditCredentialInput = z.infer<typeof EditCredentialInputSchema>;
|
|
254
253
|
/**
|
|
255
|
-
* we forbid to edit a copy
|
|
256
|
-
* only copies can have AGs, so data_id in AGs is id of a copy
|
|
257
|
-
* if $id is shared_credentials.copy_id - it is a copy
|
|
258
|
-
*/
|
|
254
|
+
* we forbid to edit a copy
|
|
255
|
+
* only copies can have AGs, so data_id in AGs is id of a copy
|
|
256
|
+
* if $id is shared_credentials.copy_id - it is a copy
|
|
257
|
+
*/
|
|
259
258
|
declare function editCredential(kwilClient: KwilActionClient, params: EditCredentialInput): Promise<void>;
|
|
260
259
|
declare const EditPublicNotesAsIssuerInputSchema: z.ZodObject<{
|
|
261
260
|
public_notes_id: z.ZodString;
|
|
@@ -263,10 +262,10 @@ declare const EditPublicNotesAsIssuerInputSchema: z.ZodObject<{
|
|
|
263
262
|
}>;
|
|
264
263
|
type EditPublicNotesAsIssuerInput = z.infer<typeof EditPublicNotesAsIssuerInputSchema>;
|
|
265
264
|
/**
|
|
266
|
-
* Be aware that @caller here is ed25519 public key, hex encoded.
|
|
267
|
-
* All other @caller in the schema are either secp256k1 or nep413
|
|
268
|
-
* This action can't be called by kwil-cli (as kwil-cli uses secp256k1 only)
|
|
269
|
-
*/
|
|
265
|
+
* Be aware that @caller here is ed25519 public key, hex encoded.
|
|
266
|
+
* All other @caller in the schema are either secp256k1 or nep413
|
|
267
|
+
* This action can't be called by kwil-cli (as kwil-cli uses secp256k1 only)
|
|
268
|
+
*/
|
|
270
269
|
declare function editPublicNotesAsIssuer(kwilClient: KwilActionClient, params: EditPublicNotesAsIssuerInput): Promise<void>;
|
|
271
270
|
declare const RemoveCredentialInputSchema: z.ZodObject<{
|
|
272
271
|
id: z.ZodUUID;
|
|
@@ -318,19 +317,19 @@ declare const CreateCredentialsByDwgInputSchema: z.ZodObject<{
|
|
|
318
317
|
}>;
|
|
319
318
|
type CreateCredentialsByDwgInput = z.infer<typeof CreateCredentialsByDwgInputSchema>;
|
|
320
319
|
/**
|
|
321
|
-
* Delegated write credential actions
|
|
322
|
-
* For access grant
|
|
323
|
-
* Check the content creator (encryptor) of credentials is the issuer that user delegated to issue the credentials
|
|
324
|
-
* Get the wallet type and public key for XRPL/NEAR wallets from database
|
|
325
|
-
* Will fail if not in the RFC3339 format
|
|
326
|
-
* Check the format and precedence
|
|
327
|
-
* Check if current block timestamp in time range allowed by write grant.
|
|
328
|
-
* @block_timestamp is a timestamp of previous block, which is can be a few seconds earlier
|
|
329
|
-
* (max is 6 seconds in current network consensus settings) then a time on a requester's machine.
|
|
330
|
-
* Also, if requester's machine has wrong time, it can be an issue.
|
|
331
|
-
* Insert original credential
|
|
332
|
-
* Insert copy credential
|
|
333
|
-
*/
|
|
320
|
+
* Delegated write credential actions
|
|
321
|
+
* For access grant
|
|
322
|
+
* Check the content creator (encryptor) of credentials is the issuer that user delegated to issue the credentials
|
|
323
|
+
* Get the wallet type and public key for XRPL/NEAR wallets from database
|
|
324
|
+
* Will fail if not in the RFC3339 format
|
|
325
|
+
* Check the format and precedence
|
|
326
|
+
* Check if current block timestamp in time range allowed by write grant.
|
|
327
|
+
* @block_timestamp is a timestamp of previous block, which is can be a few seconds earlier
|
|
328
|
+
* (max is 6 seconds in current network consensus settings) then a time on a requester's machine.
|
|
329
|
+
* Also, if requester's machine has wrong time, it can be an issue.
|
|
330
|
+
* Insert original credential
|
|
331
|
+
* Insert copy credential
|
|
332
|
+
*/
|
|
334
333
|
declare function createCredentialsByDwg(kwilClient: KwilActionClient, params: CreateCredentialsByDwgInput): Promise<void>;
|
|
335
334
|
declare const CredentialExistAsInserterInputSchema: z.ZodObject<{
|
|
336
335
|
id: z.ZodUUID;
|
|
@@ -441,13 +440,13 @@ declare const DwgMessageOutputSchema: z.ZodObject<{
|
|
|
441
440
|
}>;
|
|
442
441
|
type DwgMessageOutput = z.infer<typeof DwgMessageOutputSchema>;
|
|
443
442
|
/**
|
|
444
|
-
* WRITE GRANTS ACTIONS
|
|
445
|
-
* Must be in yyyy-mm-ddThh:mm:ssZ format
|
|
446
|
-
* Must be in yyyy-mm-ddThh:mm:ssZ format
|
|
447
|
-
* Must be in yyyy-mm-ddThh:mm:ssZ format
|
|
448
|
-
* Will fail if not in the yyyy-mm-ddThh:mm:ssZ format, and not comply to RFC3339
|
|
449
|
-
* Check the format and precedence
|
|
450
|
-
*/
|
|
443
|
+
* WRITE GRANTS ACTIONS
|
|
444
|
+
* Must be in yyyy-mm-ddThh:mm:ssZ format
|
|
445
|
+
* Must be in yyyy-mm-ddThh:mm:ssZ format
|
|
446
|
+
* Must be in yyyy-mm-ddThh:mm:ssZ format
|
|
447
|
+
* Will fail if not in the yyyy-mm-ddThh:mm:ssZ format, and not comply to RFC3339
|
|
448
|
+
* Check the format and precedence
|
|
449
|
+
*/
|
|
451
450
|
declare function dwgMessage(kwilClient: KwilActionClient, params: DwgMessageInput): Promise<DwgMessageOutput>;
|
|
452
451
|
declare const RevokeAccessGrantInputSchema: z.ZodObject<{
|
|
453
452
|
id: z.ZodUUID;
|
|
@@ -485,10 +484,10 @@ declare const GetAccessGrantsGrantedOutputSchema: z.ZodObject<{
|
|
|
485
484
|
}>;
|
|
486
485
|
type GetAccessGrantsGrantedOutput = z.infer<typeof GetAccessGrantsGrantedOutputSchema>;
|
|
487
486
|
/**
|
|
488
|
-
* As arguments can be undefined (user can not send them at all), we have to have default values: page=1, size=20
|
|
489
|
-
* Page number starts from 1, as UI usually shows to user in pagination element
|
|
490
|
-
* Ordering is consistent because we use height as first ordering parameter
|
|
491
|
-
*/
|
|
487
|
+
* As arguments can be undefined (user can not send them at all), we have to have default values: page=1, size=20
|
|
488
|
+
* Page number starts from 1, as UI usually shows to user in pagination element
|
|
489
|
+
* Ordering is consistent because we use height as first ordering parameter
|
|
490
|
+
*/
|
|
492
491
|
declare function getAccessGrantsGranted(kwilClient: KwilActionClient, params: GetAccessGrantsGrantedInput): Promise<GetAccessGrantsGrantedOutput[]>;
|
|
493
492
|
declare const GetAccessGrantsGrantedCountInputSchema: z.ZodObject<{
|
|
494
493
|
user_id: z.ZodNullable<z.ZodUUID>;
|
|
@@ -531,9 +530,9 @@ declare const CreateAgByDagForCopyInputSchema: z.ZodObject<{
|
|
|
531
530
|
}>;
|
|
532
531
|
type CreateAgByDagForCopyInput = z.infer<typeof CreateAgByDagForCopyInputSchema>;
|
|
533
532
|
/**
|
|
534
|
-
* Get the wallet type and public key for XRPL/NEAR wallets from database
|
|
535
|
-
* This works for EVM-compatible signatures only
|
|
536
|
-
*/
|
|
533
|
+
* Get the wallet type and public key for XRPL/NEAR wallets from database
|
|
534
|
+
* This works for EVM-compatible signatures only
|
|
535
|
+
*/
|
|
537
536
|
declare function createAgByDagForCopy(kwilClient: KwilActionClient, params: CreateAgByDagForCopyInput): Promise<void>;
|
|
538
537
|
declare const GetAccessGrantsForCredentialInputSchema: z.ZodObject<{
|
|
539
538
|
credential_id: z.ZodUUID;
|
|
@@ -560,9 +559,9 @@ declare const HasProfileOutputSchema: z.ZodObject<{
|
|
|
560
559
|
}>;
|
|
561
560
|
type HasProfileOutput = z.infer<typeof HasProfileOutputSchema>;
|
|
562
561
|
/**
|
|
563
|
-
* OTHER ACTIONS
|
|
564
|
-
* Should we improve it to work with near wallets too?
|
|
565
|
-
*/
|
|
562
|
+
* OTHER ACTIONS
|
|
563
|
+
* Should we improve it to work with near wallets too?
|
|
564
|
+
*/
|
|
566
565
|
declare function hasProfile(kwilClient: KwilActionClient, params: HasProfileInput): Promise<HasProfileOutput>;
|
|
567
566
|
declare const CheckBalanceInputSchema: z.ZodObject<{
|
|
568
567
|
address: z.ZodString;
|
|
@@ -584,9 +583,9 @@ declare const GetWalletWithBalanceOutputSchema: z.ZodObject<{
|
|
|
584
583
|
}>;
|
|
585
584
|
type GetWalletWithBalanceOutput = z.infer<typeof GetWalletWithBalanceOutputSchema>;
|
|
586
585
|
/**
|
|
587
|
-
* even if the @caller is not EVM address, there is no harm to try to get the balance, it will return nothing
|
|
588
|
-
* because bridge.balance can only have records with EVM addresses (it is filled from EVM-compatible contract events)
|
|
589
|
-
*/
|
|
586
|
+
* even if the @caller is not EVM address, there is no harm to try to get the balance, it will return nothing
|
|
587
|
+
* because bridge.balance can only have records with EVM addresses (it is filled from EVM-compatible contract events)
|
|
588
|
+
*/
|
|
590
589
|
declare function getWalletWithBalance(kwilClient: KwilActionClient, params: GetWalletWithBalanceInput): Promise<GetWalletWithBalanceOutput>;
|
|
591
590
|
declare const RequestWithdrawalInputSchema: z.ZodObject<{
|
|
592
591
|
token: z.ZodString;
|
|
@@ -641,4 +640,4 @@ declare const GET_GRANTS_DEFAULT_RECORDS_PER_PAGE = 10;
|
|
|
641
640
|
declare function getGrants(kwilClient: KwilActionClient, params?: Partial<GetAccessGrantsGrantedInput>): Promise<idOSGrant[]>;
|
|
642
641
|
//#endregion
|
|
643
642
|
export { DwgMessageInputSchema as $, checkBalance as $n, KwilActionClient as $r, GetUserAsInserterOutputSchema as $t, AddWalletInputSchema as A, ShareAttributeInput as An, removeCredential as Ar, GetCredentialOwnedOutput as At, CredentialExistAsInserterInputSchema as B, WALLET_TYPES as Bn, upsertWalletAsInserter as Br, GetCredentialsSharedByUserOutput as Bt, AddDelegateAsOwnerInput as C, RequestBalanceWithdrawalInputSchema as Cn, getUser as Cr, GetAccessGrantsOwnedOutputSchema as Ct, AddUserAsInserterInput as D, RescindSharedCredentialInputSchema as Dn, hasLockedAccessGrants as Dr, GetAttributesOutputSchema as Dt, AddInserterAsOwnerInputSchema as E, RescindSharedCredentialInput as En, getWallets as Er, GetAttributesOutput as Et, CreateAgByDagForCopyInput as F, UpdateUserPubKeyAsInserterInputSchema as Fn, revokeAccessGrant as Fr, GetCredentialSharedOutputSchema as Ft, DagMessageOutput as G, actionSchema as Gn, CustomKwilSigner as Gr, GetIssuerFeeOutputSchema as Gt, CredentialExistAsInserterOutputSchema as H, actionCostingFee as Hn, getNearFullAccessPublicKeys as Hr, GetIssuerFeeInput as Ht, CreateAgByDagForCopyInputSchema as I, UpsertCredentialAsInserterInput as In, shareAttribute as Ir, GetCredentialsOutput as It, DeleteDelegateAsOwnerInput as J, addCredential as Jn, SignerAddress as Jr, GetSiblingCredentialIdOutput as Jt, DagMessageOutputSchema as K, addAttribute as Kn, KwilSigner$1 as Kr, GetSiblingCredentialIdInput as Kt, CreateCredentialsByDwgInput as L, UpsertCredentialAsInserterInputSchema as Ln, shareCredential as Lr, GetCredentialsOutputSchema as Lt, CheckBalanceInputSchema as M, ShareCredentialInput as Mn, requestBalanceWithdrawal as Mr, GetCredentialSharedInput as Mt, CheckBalanceOutput as N, ShareCredentialInputSchema as Nn, requestWithdrawal as Nr, GetCredentialSharedInputSchema as Nt, AddUserAsInserterInputSchema as O, RevokeAccessGrantInput as On, hasProfile as Or, GetCredentialOwnedInput as Ot, CheckBalanceOutputSchema as P, UpdateUserPubKeyAsInserterInput as Pn, rescindSharedCredential as Pr, GetCredentialSharedOutput as Pt, DwgMessageInput as Q, addWallet as Qn, createServerKwilSigner as Qr, GetUserAsInserterOutput as Qt, CreateCredentialsByDwgInputSchema as R, UpsertWalletAsInserterInput as Rn, updateUserPubKeyAsInserter as Rr, GetCredentialsSharedByUserInput as Rt, AddCredentialInputSchema as S, RequestBalanceWithdrawalInput as Sn, getSiblingCredentialId as Sr, GetAccessGrantsOwnedOutput as St, AddInserterAsOwnerInput as T, RequestWithdrawalInputSchema as Tn, getWalletWithBalance as Tr, GetAllowanceOutputSchema as Tt, DagMessageInput as U, actionCostingGas as Un, implicitAddressFromPublicKey as Ur, GetIssuerFeeInputSchema as Ut, CredentialExistAsInserterOutput as V, WalletType as Vn, walletTypeSchema as Vr, GetCredentialsSharedByUserOutputSchema as Vt, DagMessageInputSchema as W, actionCostingIdosToken as Wn, signNearMessage as Wr, GetIssuerFeeOutput as Wt, DeleteInserterAsOwnerInput as X, addInserterAsOwner as Xn, Wallet$2 as Xr, GetUserAsInserterInput as Xt, DeleteDelegateAsOwnerInputSchema as Y, addDelegateAsOwner as Yn, SignerPublicKey as Yr, GetSiblingCredentialIdOutputSchema as Yt, DeleteInserterAsOwnerInputSchema as Z, addUserAsInserter as Zn, createClientKwilSigner as Zr, GetUserAsInserterInputSchema as Zt, AddAttributeAsInserterInput as _, RemoveAttributeInputSchema as _n, getCredentialOwned as _r, GetAccessGrantsGrantedCountOutputSchema as _t, idOSCredentialListItem as a, GetWalletWithBalanceOutputSchema as an, deleteInserterAsOwner as ar, EditCredentialInput as at, AddAttributeInputSchema as b, RemoveWalletInput as bn, getCredentialsSharedByUser as br, GetAccessGrantsGrantedOutput as bt, idOSUser as c, HasLockedAccessGrantsInput as cn, editCredential as cr, EditPublicNotesAsIssuerInputSchema as ct, removeWallets as d, HasLockedAccessGrantsOutputSchema as dn, getAccessGrantsForCredential as dr, GetAccessGrantsForCredentialInputSchema as dt, createNodeKwilClient as ei, GetUserOutput as en, createAgByDagForCopy as er, DwgMessageOutput as et, ActionCostingFeeInput as f, HasProfileInput as fn, getAccessGrantsGranted as fr, GetAccessGrantsForCredentialOutput as ft, ActionSchemaElement as g, RemoveAttributeInput as gn, getAttributes as gr, GetAccessGrantsGrantedCountOutput as gt, ActionCostingIdosTokenInputSchema as h, HasProfileOutputSchema as hn, getAllowance as hr, GetAccessGrantsGrantedCountInputSchema as ht, idOSCredential as i, GetWalletWithBalanceOutput as in, deleteDelegateAsOwner as ir, EditAttributeInputSchema as it, CheckBalanceInput as j, ShareAttributeInputSchema as jn, removeWallet as jr, GetCredentialOwnedOutputSchema as jt, AddWalletInput as k, RevokeAccessGrantInputSchema as kn, removeAttribute as kr, GetCredentialOwnedInputSchema as kt, idOSUserAttribute as l, HasLockedAccessGrantsInputSchema as ln, editPublicNotesAsIssuer as lr, EncryptionPasswordStore as lt, ActionCostingIdosTokenInput as m, HasProfileOutput as mn, getAccessGrantsOwned as mr, GetAccessGrantsGrantedCountInput as mt, addWallets as n, GetWalletWithBalanceInput as nn, credentialExistAsInserter as nr, ENCRYPTION_PASSWORD_STORES as nt, idOSDelegatedWriteGrant as o, GetWalletsOutput as on, dwgMessage as or, EditCredentialInputSchema as ot, ActionCostingFeeInputSchema as p, HasProfileInputSchema as pn, getAccessGrantsGrantedCount as pr, GetAccessGrantsForCredentialOutputSchema as pt, DataType as q, addAttributeAsInserter as qn, KwilSignerType as qr, GetSiblingCredentialIdInputSchema as qt, getGrants as r, GetWalletWithBalanceInputSchema as rn, dagMessage as rr, EditAttributeInput as rt, idOSGrant as s, GetWalletsOutputSchema as sn, editAttribute as sr, EditPublicNotesAsIssuerInput as st, GET_GRANTS_DEFAULT_RECORDS_PER_PAGE as t, createWebKwilClient as ti, GetUserOutputSchema as tn, createCredentialsByDwg as tr, DwgMessageOutputSchema as tt, idOSWallet as u, HasLockedAccessGrantsOutput as un, encryptionPasswordStoreSchema as ur, GetAccessGrantsForCredentialInput as ut, AddAttributeAsInserterInputSchema as v, RemoveCredentialInput as vn, getCredentialShared as vr, GetAccessGrantsGrantedInput as vt, AddDelegateAsOwnerInputSchema as w, RequestWithdrawalInput as wn, getUserAsInserter as wr, GetAllowanceOutput as wt, AddCredentialInput as x, RemoveWalletInputSchema as xn, getIssuerFee as xr, GetAccessGrantsGrantedOutputSchema as xt, AddAttributeInput as y, RemoveCredentialInputSchema as yn, getCredentials as yr, GetAccessGrantsGrantedInputSchema as yt, CredentialExistAsInserterInput as z, UpsertWalletAsInserterInputSchema as zn, upsertCredentialAsInserter as zr, GetCredentialsSharedByUserInputSchema as zt };
|
|
644
|
-
//# sourceMappingURL=index-
|
|
643
|
+
//# sourceMappingURL=index-iqkJfgWf.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-iqkJfgWf.d.mts","names":[],"sources":["../src/create-kwil-client.ts","../src/create-kwil-signer.ts","../src/near/create-near-wallet-kwil-signer.ts","../src/actions/actions.ts","../src/actions/index.ts"],"mappings":";;;;;;;;;;;KAeK;EACH;EACA;;KAGG,qBAAqB;KACrB,mBAAmB;KAEnB,uBACF,QAAQ;EACP,MAAM;EAEN,QAAQ,OAAO,YAAY;;KAI1B,8BAA8B,kBAAkB;KAEhD,0BACF,QAAQ,aAAa,kBAAkB;EAAU;;KAG/C,iCAAiC,qBAAqB;;;;;cAM9C;;EACX,SAAS;WACA,QAAQ,WAAW;EAE5B,YAAY,QAAQ,WAAW;;;;EAyB/B,KAAW,aACT,QAAQ,6BACR,SAAQ,yBACP,QAAQ;;;;EAeX,QACE,QAAQ,gCACR,SAAQ,wBACR,wBACC;EAaH,UAAU,QAAQ;;;;;cA6BP,uBAAuB,QAAQ,2BAA2B,QAAQ;;;;cAMlE,sBAAsB,QAAQ,2BAA2B,QAAQ;;;KCrHlE,WACR,WACA,gBACA,SACA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AmB,QAAQ;iBASpD,iBAAiB,YAAY,mBAAmB;cAQzD,mCAAmC,EAAE;EAChD,QAAQ,EAAE;;KAKA,8BAA8B,EAAE,aAAa;iBAEnC,uBACpB,YAAY,kBACZ,QAAQ,8BACP;cASU,yBAAyB,EAAE;EACtC,eAAe,EAAE;;KAKP,oBAAoB,EAAE,aAAa;cAElC,0BAA0B,EAAE;EACvC,YAAY,EAAE;;KAKJ,qBAAqB,EAAE,aAAa;iBAE1B,aACpB,YAAY,kBACZ,QAAQ,oBACP,QAAQ;cAUE,6BAA6B,EAAE;EAC1C,eAAe,EAAE;;KAKP,wBAAwB,EAAE,aAAa;iBAE7B,iBACpB,YAAY,kBACZ,QAAQ,wBACP;cASU,qCAAqC,EAAE;EAClD,OAAO,EAAE;EACT,gBAAgB,EAAE;;KAMR,gCAAgC,EAAE,aAAa;iBAErC,yBACpB,YAAY,kBACZ,QAAQ,gCACP;;;KCznES,WAAW;KACX,YAAY;KACZ,iBAAiB;KACjB,yBAAyB;KACzB,oBAAoB;KACpB,aAAa;KACb,0BAA0B;iBAEhB,WACpB,YAAY,kBACZ,SAAS,mBACR;iBAImB,cAAc,YAAY,kBAAkB,gBAAgB;cAIrE;iBAES,UACpB,YAAY,kBACZ,SAAQ,QAAQ,+BAKf,QAAQ"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $r as KwilActionClient, Gr as CustomKwilSigner, Hr as getNearFullAccessPublicKeys, Jr as SignerAddress, Kr as KwilSigner, Qr as createServerKwilSigner, Ur as implicitAddressFromPublicKey, Wr as signNearMessage, Xr as Wallet, Yr as SignerPublicKey, Zr as createClientKwilSigner, ei as createNodeKwilClient, qr as KwilSignerType, ti as createWebKwilClient } from "./index-
|
|
1
|
+
import { $r as KwilActionClient, Gr as CustomKwilSigner, Hr as getNearFullAccessPublicKeys, Jr as SignerAddress, Kr as KwilSigner, Qr as createServerKwilSigner, Ur as implicitAddressFromPublicKey, Wr as signNearMessage, Xr as Wallet, Yr as SignerPublicKey, Zr as createClientKwilSigner, ei as createNodeKwilClient, qr as KwilSignerType, ti as createWebKwilClient } from "./index-iqkJfgWf.mjs";
|
|
2
2
|
export { CustomKwilSigner, KwilActionClient, KwilSigner, KwilSignerType, SignerAddress, SignerPublicKey, Wallet, createClientKwilSigner, createNodeKwilClient, createServerKwilSigner, createWebKwilClient, getNearFullAccessPublicKeys, implicitAddressFromPublicKey, signNearMessage };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { actionSchema } from "./actions/index.mjs";
|
|
2
|
-
import { t as FaceSignSignerProvider } from "./facesign-signer-
|
|
2
|
+
import { t as FaceSignSignerProvider } from "./facesign-signer-qzCcwunk.mjs";
|
|
3
3
|
import { getXrpPublicKey, getXrpTxHash, looksLikeXrpWallet } from "./xrp/utils.mjs";
|
|
4
4
|
import { KwilSigner, KwilSigner as KwilSigner$1, NodeKwil, WebKwil } from "@idos-network/kwil-js";
|
|
5
5
|
import invariant from "tiny-invariant";
|
|
@@ -107,7 +107,8 @@ const detectNearNetwork = (accountId) => {
|
|
|
107
107
|
return "testnet";
|
|
108
108
|
};
|
|
109
109
|
const getNearConnectionConfig = (accountId) => {
|
|
110
|
-
const
|
|
110
|
+
const network = detectNearNetwork(accountId);
|
|
111
|
+
const networkConfig = NEAR_NETWORKS[network];
|
|
111
112
|
return {
|
|
112
113
|
networkId: networkConfig.networkId,
|
|
113
114
|
nodeUrl: networkConfig.nodeUrl
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["#createActionInputs","#actionTypes","KwilSigner","KwilSigner","KwilSigner"],"sources":["../src/create-kwil-client.ts","../src/near/get-config.ts","../src/near/create-near-wallet-kwil-signer.ts","../src/near/nep413.ts","../src/xrp/signer.ts","../src/create-kwil-signer.ts"],"sourcesContent":["import type { Config } from \"@idos-network/kwil-js/dist/api_client/config\";\nimport type {\n ActionBody,\n CallBody,\n PositionalParams,\n} from \"@idos-network/kwil-js/dist/core/action\";\nimport type { DataInfo } from \"@idos-network/kwil-js/dist/core/database\";\n\nimport { type KwilSigner, NodeKwil, WebKwil } from \"@idos-network/kwil-js\";\nimport invariant from \"tiny-invariant\";\n\nimport type { ActionSchemaElement } from \"./actions\";\n\nimport { actionSchema } from \"./actions\";\n\ntype CreateKwilClientParams = {\n chainId?: string;\n nodeUrl: string;\n};\n\ntype KwilActions = typeof actionSchema;\ntype ActionName = keyof KwilActions;\n\ntype AllKwilCallAction = {\n [Name in ActionName]: {\n name: Name;\n // oxlint-disable-next-line typescript/no-explicit-any -- This is fine\n inputs: Record<KwilActions[Name][number][\"name\"], any>;\n };\n};\n\ntype KwilCallActionRequestParams = AllKwilCallAction[ActionName];\n\ntype AllKwilExecuteAction = {\n [Name in ActionName]: AllKwilCallAction[Name] & { description: string };\n};\n\ntype KwilExecuteActionRequestParams = AllKwilExecuteAction[ActionName];\n\n/**\n * A client for interacting with kwil with type-safe abstractions for `call` and `execute`.\n * Has utility methods for creating actions and setting a signer.\n */\nexport class KwilActionClient {\n signer?: KwilSigner;\n readonly client: NodeKwil | WebKwil;\n\n constructor(client: NodeKwil | WebKwil) {\n this.client = client;\n }\n\n #createActionInputs(actionName: string, params: Record<string, unknown> = {}): PositionalParams {\n if (!params || !Object.keys(params).length) return [];\n\n const args = (actionSchema as Record<string, readonly ActionSchemaElement[]>)[actionName];\n\n return args.map(({ name }) => {\n const value = params[name];\n // Handle falsy values appropriately\n if (value === \"\" || value === 0) return value;\n return value ?? null;\n }) as PositionalParams;\n }\n\n #actionTypes(actionName: string): DataInfo[] {\n const args = actionSchema[actionName];\n return args.map((arg) => arg.type);\n }\n\n /**\n * Calls an action on the kwil nodes. This similar to `GET` like request.\n */\n async call<T = unknown>(\n params: KwilCallActionRequestParams,\n signer: KwilSigner | undefined = this.signer,\n ): Promise<T> {\n const action: CallBody = {\n name: params.name,\n namespace: \"main\",\n inputs: this.#createActionInputs(params.name, params.inputs),\n types: this.#actionTypes(params.name),\n };\n\n const response = await this.client.call(action as CallBody, signer);\n return response?.data?.result as T;\n }\n\n /**\n * Executes an action on the kwil nodes. This similar to `POST` like request.\n */\n async execute(\n params: KwilExecuteActionRequestParams,\n signer: KwilSigner | undefined = this.signer,\n synchronous = true,\n ): Promise<string | undefined> {\n invariant(signer, \"Signer is not set, you must set it before executing an action\");\n const action: ActionBody = {\n name: params.name,\n namespace: \"main\",\n description: params.description,\n inputs: [this.#createActionInputs(params.name, params.inputs)],\n types: this.#actionTypes(params.name),\n };\n const response = await this.client.execute(action, signer, synchronous);\n return response.data?.tx_hash;\n }\n\n setSigner(signer: KwilSigner | undefined): void {\n this.signer = signer;\n }\n\n /**\n * Creates action inputs from the given parameters that are used in the action body.\n */\n}\n\nconst DEFAULT_TIMEOUT = 30_000;\n\nconst createKwilClient =\n (Cls: new (opts: Config) => NodeKwil | WebKwil) =>\n async ({ nodeUrl: kwilProvider, chainId }: CreateKwilClientParams): Promise<KwilActionClient> => {\n const _kwil = new Cls({ kwilProvider, chainId: \"\" });\n // oxlint-disable-next-line no-param-reassign -- Default value fallback\n chainId ||= (await _kwil.chainInfo({ disableWarning: true })).data?.chain_id;\n invariant(chainId, \"Can't discover `chainId`. You must pass it explicitly.\");\n\n const client = new KwilActionClient(\n new Cls({ kwilProvider, chainId, timeout: DEFAULT_TIMEOUT }),\n );\n\n return client;\n };\n\n/**\n * Create a kwil client for node.js environment\n */\nexport const createNodeKwilClient: (params: CreateKwilClientParams) => Promise<KwilActionClient> =\n createKwilClient(NodeKwil);\n\n/**\n * Create a kwil client for browser environment\n */\nexport const createWebKwilClient: (params: CreateKwilClientParams) => Promise<KwilActionClient> =\n createKwilClient(WebKwil);\n","// Network configuration mapping\nconst NEAR_NETWORKS = {\n mainnet: {\n networkId: \"mainnet\",\n nodeUrl: \"https://rpc.mainnet.near.org\",\n },\n testnet: {\n networkId: \"testnet\",\n nodeUrl: \"https://rpc.testnet.near.org\",\n },\n betanet: {\n networkId: \"betanet\",\n nodeUrl: \"https://rpc.betanet.near.org\",\n },\n shardnet: {\n networkId: \"shardnet\",\n nodeUrl: \"https://rpc.shardnet.near.org\",\n },\n} as const;\n\n// Function to detect NEAR network from account ID\nexport const detectNearNetwork = (accountId: string): keyof typeof NEAR_NETWORKS => {\n if (accountId.endsWith(\".near\")) return \"mainnet\";\n if (accountId.endsWith(\".testnet\")) return \"testnet\";\n if (accountId.endsWith(\".betanet\")) return \"betanet\";\n if (accountId.endsWith(\".shardnet\")) return \"shardnet\";\n\n // Default to testnet for development, mainnet for production\n return \"testnet\";\n};\n\n// Function to get connection config based on account ID\nexport const getNearConnectionConfig = (\n accountId: string,\n): { networkId: string; nodeUrl: string } => {\n const network = detectNearNetwork(accountId);\n const networkConfig = NEAR_NETWORKS[network];\n\n return {\n networkId: networkConfig.networkId,\n nodeUrl: networkConfig.nodeUrl,\n };\n};\n","import type { Store } from \"@idos-network/utils/store\";\nimport type {\n Wallet as NearWallet,\n SignedMessage,\n SignMessageParams,\n} from \"@near-wallet-selector/core\";\nimport type { connect as connectT } from \"near-api-js\";\nimport type { AccessKeyList } from \"near-api-js/lib/providers/provider\";\n\nimport { KwilSigner } from \"@idos-network/kwil-js\";\nimport {\n base64Decode,\n binaryWriteUint16BE,\n borshSerialize,\n bs58Decode,\n bytesConcat,\n hexEncode,\n utf8Decode,\n} from \"@idos-network/utils/codecs\";\n\nimport type { KwilActionClient } from \"../create-kwil-client\";\n\nimport { getNearConnectionConfig } from \"./get-config\";\n\nconst NEAR_WALLET_TYPES: string[] = [\n \"browser\",\n \"injected\",\n \"instant-link\",\n \"hardware\",\n \"bridge\",\n] satisfies NearWallet[\"type\"][];\n\nexport function looksLikeNearWallet(signer: unknown): signer is NearWallet {\n return (\n signer !== null &&\n typeof signer === \"object\" &&\n \"id\" in signer &&\n \"metadata\" in signer &&\n \"type\" in signer &&\n typeof signer.type === \"string\" &&\n NEAR_WALLET_TYPES.includes(signer.type)\n );\n}\n\nclass KwilNonce {\n bytes: Uint8Array;\n\n constructor(length = 32) {\n // We're in the browser, so there's a window.crypto for sure.\n /* global crypto */\n this.bytes = crypto.getRandomValues(new Uint8Array(length));\n }\n\n get clampUTF8() {\n return this.bytes.map((byte) => byte & 127);\n }\n}\n\n/**\n * Creates a signer function that can be used to sign messages with a NEAR wallet\n */\nfunction createNearWalletSigner(\n wallet: NearWallet,\n recipient: string,\n): (message: string | Uint8Array) => Promise<Uint8Array> {\n return async (message: string | Uint8Array): Promise<Uint8Array> => {\n const messageString = typeof message === \"string\" ? message : utf8Decode(message);\n\n if (!wallet.signMessage) {\n throw new Error(\"Only wallets with signMessage are supported.\");\n }\n\n const nonceSuggestion = Buffer.from(new KwilNonce(32).bytes);\n\n const {\n nonce = nonceSuggestion,\n signature,\n // @ts-expect-error Signatures don't seem to be updated for NEP413 yet.\n callbackUrl,\n // oxlint-disable-next-line typescript/no-non-null-assertion -- Only non-signing wallets return void.\n } = (await (\n wallet.signMessage as (\n _: SignMessageParams,\n ) => Promise<SignedMessage & { nonce?: Uint8Array }>\n )({\n message: messageString,\n recipient,\n nonce: nonceSuggestion,\n }))!;\n\n const nep413BorschSchema = {\n struct: {\n tag: \"u32\",\n message: \"string\",\n nonce: { array: { type: \"u8\", len: 32 } },\n recipient: \"string\",\n callbackUrl: { option: \"string\" },\n },\n };\n\n const nep413BorshParams = {\n tag: 2147484061,\n message: messageString,\n nonce: Array.from(nonce),\n recipient,\n callbackUrl,\n };\n\n const nep413BorshPayload = borshSerialize(nep413BorschSchema, nep413BorshParams);\n const result = bytesConcat(\n binaryWriteUint16BE(nep413BorshPayload.length),\n nep413BorshPayload,\n base64Decode(signature),\n );\n\n return result;\n };\n}\n\nexport function implicitAddressFromPublicKey(publicKey: string): string {\n const key_without_prefix = publicKey.replace(/^ed25519:/, \"\");\n return hexEncode(bs58Decode(key_without_prefix));\n}\n\nexport async function getNearFullAccessPublicKeys(\n namedAddress: string,\n): Promise<string[] | undefined> {\n let connect: typeof connectT;\n try {\n connect = (await import(\"near-api-js\")).connect;\n } catch (_e) {\n throw new Error(\"Can't load near-api-js\");\n }\n const connectionConfig = getNearConnectionConfig(namedAddress);\n const nearConnection = await connect(connectionConfig);\n\n try {\n const response: AccessKeyList = await nearConnection.connection.provider.query({\n request_type: \"view_access_key_list\",\n finality: \"final\",\n account_id: namedAddress,\n });\n return response.keys\n .filter((element) => element.access_key.permission === \"FullAccess\")\n ?.map((i) => i.public_key);\n } catch {\n // `Near` failed if namedAddress contains uppercase symbols\n return;\n }\n}\n\nexport async function signNearMessage(\n wallet: NearWallet,\n message: string,\n recipient = \"idos.network\",\n): Promise<string> {\n const signer = createNearWalletSigner(wallet, recipient);\n const signedPayload = await signer(message);\n return hexEncode(signedPayload);\n}\n\nexport async function createNearWalletKwilSigner(\n wallet: NearWallet,\n currentAddress: string,\n store: Store,\n kwilClient: KwilActionClient,\n recipient = \"idos.network\",\n): Promise<{ kwilSigner: KwilSigner; publicKey: string }> {\n if (!wallet.signMessage) throw new Error(\"Only wallets with signMessage are supported.\");\n\n if (wallet.id === \"my-near-wallet\") {\n const { accountId, signature, publicKey, error } = Object.fromEntries(\n new URLSearchParams(window.location.hash.slice(1)).entries(),\n );\n\n if (signature) {\n await store.set(\"signer-address\", accountId);\n await store.set(\"signer-public-key\", publicKey);\n }\n\n const signMessageOriginal = wallet.signMessage.bind(wallet);\n\n wallet.signMessage = async ({\n message,\n recipient,\n }: SignMessageParams): Promise<SignedMessage & { nonce?: Uint8Array }> => {\n if (error) return Promise.reject();\n\n const lastMessage = await store.get<string>(\"sign-last-message\");\n const lastNonce = await store.get<Uint8Array>(\"sign-last-nonce\");\n\n if (signature && message === lastMessage && lastNonce) {\n const nonce = Buffer.from(lastNonce);\n const callbackUrl = await store.get<string>(\"sign-last-url\");\n\n return Promise.resolve({\n accountId: currentAddress,\n publicKey,\n signature,\n nonce,\n message,\n callbackUrl,\n } as SignedMessage);\n }\n\n const callbackUrl = window.location.href;\n const nonce = Buffer.from(new KwilNonce(32).clampUTF8);\n\n await store.set(\"sign-last-message\", message);\n await store.set(\"sign-last-nonce\", Array.from(nonce));\n await store.set(\"sign-last-url\", callbackUrl);\n\n signMessageOriginal({ message, nonce, recipient, callbackUrl });\n\n return new Promise(() => ({}) as SignedMessage);\n };\n }\n\n const storedAddress = await store.get<string>(\"signer-address\");\n\n let publicKey = await store.get<string>(\"signer-public-key\");\n\n if (storedAddress !== currentAddress || !publicKey) {\n store.reset();\n // To avoid re-using the old signer's kgw cookie.\n // When kwil-js supports multi cookies, we can remove this.\n await kwilClient.client.auth.logoutKGW();\n\n const message = \"idOS authentication\";\n const nonce = Buffer.from(new KwilNonce(32).bytes);\n const signResult = await wallet.signMessage({ message, recipient, nonce });\n if (!signResult) throw new Error(\"signMessage returned no result\");\n ({ publicKey } = signResult);\n\n await store.set(\"signer-address\", currentAddress);\n await store.set(\"signer-public-key\", publicKey);\n }\n\n const signer = createNearWalletSigner(wallet, recipient);\n\n return {\n kwilSigner: new KwilSigner(signer, implicitAddressFromPublicKey(publicKey), \"nep413\"),\n publicKey,\n };\n}\n","import type { KeyPair } from \"near-api-js\";\n\nimport {\n binaryWriteUint16BE,\n borshSerialize,\n bytesConcat,\n sha256Hash,\n utf8Decode,\n} from \"@idos-network/utils/codecs\";\n\nexport function kwilNep413Signer(\n recipient: string,\n): (keyPair: KeyPair) => (messageBytes: Uint8Array) => Promise<Uint8Array> {\n return (keyPair: KeyPair) =>\n async (messageBytes: Uint8Array): Promise<Uint8Array> => {\n const message = utf8Decode(messageBytes);\n const nonceLength = 32;\n const nonce = crypto.getRandomValues(new Uint8Array(nonceLength));\n\n const nep413BorschSchema = {\n struct: {\n message: \"string\",\n nonce: { array: { type: \"u8\", len: nonceLength } },\n recipient: \"string\",\n callbackUrl: { option: \"string\" },\n },\n } as const;\n\n const tag = 2147484061; // 2**31 + 413\n\n const { signature } = keyPair.sign(\n sha256Hash(\n bytesConcat(\n borshSerialize(\"u32\", tag),\n borshSerialize(nep413BorschSchema, { message, nonce, recipient }),\n ),\n ),\n );\n\n const kwilNep413BorschSchema = {\n struct: {\n tag: \"u32\",\n ...nep413BorschSchema.struct,\n },\n };\n\n const kwilNep413BorshParams = {\n tag,\n message,\n nonce,\n recipient,\n };\n\n const kwilNep413BorshPayload = borshSerialize(kwilNep413BorschSchema, kwilNep413BorshParams);\n\n return bytesConcat(\n binaryWriteUint16BE(kwilNep413BorshPayload.length),\n kwilNep413BorshPayload,\n signature,\n );\n };\n}\n","import type * as GemWallet from \"@gemwallet/api\";\nimport type { Store } from \"@idos-network/utils/store\";\nimport type { Xumm } from \"xumm\";\n\nimport { KwilSigner } from \"@idos-network/kwil-js\";\n\nimport type { KwilActionClient } from \"../create-kwil-client\";\n\nimport { getXrpTxHash } from \"./utils\";\n\nexport async function createXrpKwilSigner(\n wallet: Xumm | typeof GemWallet,\n currentAddress: string,\n store: Store,\n kwilClient: KwilActionClient,\n walletPublicKey: string,\n): Promise<KwilSigner> {\n const storedAddress = await store.get<string>(\"signer-address\");\n const storePublicKey = await store.get<string>(\"signer-public-key\");\n\n if (storedAddress !== currentAddress || (storePublicKey && storePublicKey !== walletPublicKey)) {\n try {\n // HEADS UP: for some reason logoutKGW fails on xrp\n // storePublicKey && await kwilClient.client.auth.logoutKGW();\n console.log(\"logoutKGW\", kwilClient);\n } catch (error) {\n console.error(\"Failed to logout KGW:\", error);\n }\n }\n\n await store.set(\"signer-address\", currentAddress);\n await store.set(\"signer-public-key\", walletPublicKey);\n\n const signer = async (message: string | Uint8Array): Promise<Uint8Array> => {\n const signature = await getXrpTxHash(message, wallet);\n if (!signature) {\n throw new Error(\"Failed to sign transaction with XRP\");\n }\n return Buffer.from(signature, \"hex\");\n };\n\n return new KwilSigner(signer, walletPublicKey, \"xrpl\");\n}\n","import type { Store } from \"@idos-network/utils/store\";\nimport type { Wallet as NearWallet } from \"@near-wallet-selector/core\";\nimport type { Keypair as StellarKeypair } from \"@stellar/stellar-sdk\";\nimport type { Wallet as EthersWallet, JsonRpcSigner } from \"ethers\";\nimport type { KeyPair as NearKeyPair } from \"near-api-js\";\nimport type { KeyPair as XrpKeyPair } from \"ripple-keypairs/src/types\";\n\nimport { KwilSigner } from \"@idos-network/kwil-js\";\nimport { bs58Encode, hexDecode, hexEncode } from \"@idos-network/utils/codecs\";\nimport nacl from \"tweetnacl\";\n\nimport type { WalletType } from \"./actions\";\nimport type { KwilActionClient } from \"./create-kwil-client\";\n\nimport { FaceSignSignerProvider } from \"./facesign/facesign-signer\";\nimport {\n createNearWalletKwilSigner,\n implicitAddressFromPublicKey,\n looksLikeNearWallet,\n} from \"./near/create-near-wallet-kwil-signer\";\nimport { kwilNep413Signer } from \"./near/nep413\";\nimport { createXrpKwilSigner } from \"./xrp/signer\";\nimport { getXrpPublicKey, looksLikeXrpWallet } from \"./xrp/utils\";\n\nexport { KwilSigner } from \"@idos-network/kwil-js\";\nexport type Wallet =\n | EthersWallet\n | JsonRpcSigner\n | NearWallet\n | CustomKwilSigner\n | FaceSignSignerProvider;\n\n/**\n * Helper function to check if the given object is a `nacl.SignKeyPair`.\n */\nfunction isNaclSignKeyPair(object: unknown): object is nacl.SignKeyPair {\n return (\n object !== null &&\n typeof object === \"object\" &&\n \"publicKey\" in object &&\n object.publicKey instanceof Uint8Array &&\n object.publicKey.length === nacl.sign.publicKeyLength &&\n \"secretKey\" in object &&\n object.secretKey instanceof Uint8Array &&\n object.secretKey.length === nacl.sign.secretKeyLength\n );\n}\n\n/**\n * Helper function to check if the given object is a NEAR KeyPair.\n */\nfunction isNearKeyPair(object: unknown): object is NearKeyPair {\n return (\n object !== null &&\n typeof object === \"object\" &&\n \"getPublicKey\" in object &&\n \"sign\" in object &&\n typeof object.getPublicKey === \"function\" &&\n typeof object.sign === \"function\"\n );\n}\n\n/**\n * Helper function to check if the given object is a Stellar Keypair.\n */\nfunction isStellarKeyPair(object: unknown): object is StellarKeypair {\n return (\n object !== null &&\n typeof object === \"object\" &&\n \"publicKey\" in object &&\n \"sign\" in object &&\n \"canSign\" in object &&\n typeof object.publicKey === \"function\" &&\n typeof object.sign === \"function\" &&\n typeof object.canSign === \"function\"\n );\n}\n\nexport interface CustomKwilSigner extends KwilSigner {\n publicAddress: string;\n signatureType: string;\n publicKey: string;\n walletType: string;\n signMessage: (message: Uint8Array | string) => Promise<Uint8Array>;\n}\n\nfunction isCustomKwilSigner(object: unknown): object is CustomKwilSigner {\n return (\n object !== null &&\n typeof object === \"object\" &&\n \"publicAddress\" in object &&\n \"signatureType\" in object &&\n \"publicKey\" in object &&\n \"signMessage\" in object\n );\n}\n\n/**\n * Helper function to check if the given object is a XRP KeyPair (Server key pairs only).\n */\nfunction isXrplKeyPair(object: unknown): object is XrpKeyPair {\n return !!object && typeof object === \"object\" && \"privateKey\" in object && \"publicKey\" in object;\n}\n\nexport type KwilSignerType =\n | NearKeyPair\n | EthersWallet\n | nacl.SignKeyPair\n | JsonRpcSigner\n | StellarKeypair\n | XrpKeyPair;\n\nexport type SignerAddress = string;\nexport type SignerPublicKey = string | undefined;\n\n/**\n * Creates a `KwilSigner` and its associated `SignerAddress`.\n *\n * This function is explicitly marked as being for backend use only because it doesn't reset\n * the KGW cookie when logging out and re-logging in with a different wallet.\n */\nexport async function createServerKwilSigner(\n signer: KwilSignerType,\n): Promise<[KwilSigner, SignerAddress]> {\n if (isNaclSignKeyPair(signer)) {\n return [\n new KwilSigner(\n async (msg: Uint8Array) => nacl.sign.detached(msg, signer.secretKey),\n signer.publicKey,\n \"ed25519\",\n ),\n implicitAddressFromPublicKey(bs58Encode(signer.publicKey)),\n ];\n }\n\n if (isNearKeyPair(signer)) {\n const publicKey = implicitAddressFromPublicKey(signer.getPublicKey().toString());\n return [\n new KwilSigner(kwilNep413Signer(\"idos-issuer\")(signer), publicKey, \"nep413\"),\n publicKey,\n ];\n }\n\n if (isStellarKeyPair(signer)) {\n const publicKeyString = signer.publicKey();\n const rawPublicKey = signer.rawPublicKey();\n return [\n new KwilSigner(\n async (msg: Uint8Array) => signer.sign(Buffer.from(msg)),\n rawPublicKey,\n \"ed25519\",\n ),\n publicKeyString,\n ];\n }\n\n if (isXrplKeyPair(signer)) {\n let xrpKeypair: typeof import(\"ripple-keypairs\");\n\n try {\n xrpKeypair = await import(\"ripple-keypairs\");\n } catch (e) {\n throw new Error(\"Can't load ripple-keypairs\", { cause: e });\n }\n\n return [\n new KwilSigner(\n async (msg: Uint8Array) => hexDecode(xrpKeypair.sign(hexEncode(msg), signer.privateKey)),\n signer.publicKey,\n \"xrpl\",\n ),\n signer.publicKey,\n ];\n }\n\n if (\"address\" in signer) {\n return [new KwilSigner(signer, signer.address), signer.address];\n }\n\n // Force the check that `signer` is never.\n // If these lines start complaining, that means we're missing an `if` above.\n return ((_: never) => {\n throw new Error(\"Invalid `signer` type\");\n })(signer);\n}\n\nexport async function createClientKwilSigner(\n store: Store,\n kwilClient: KwilActionClient,\n wallet: Wallet,\n): Promise<[KwilSigner, SignerAddress, SignerPublicKey, WalletType]> {\n if (\"connect\" in wallet && \"address\" in wallet) {\n // oxlint-disable-next-line no-param-reassign -- Narrowing the type on purpose\n wallet = wallet as unknown as JsonRpcSigner;\n const currentAddress = await wallet.getAddress();\n\n const storedAddress = await store.get<string>(\"signer-address\");\n\n if (storedAddress !== currentAddress) {\n // To avoid re-using the old signer's kgw cookie.\n // When kwil-js supports multi cookies, we can remove this.\n store.set(\"signer-address\", currentAddress);\n try {\n await kwilClient.client.auth.logoutKGW();\n } catch (error) {\n console.log(\"error logoutKGW\", error);\n }\n }\n\n return [new KwilSigner(wallet, currentAddress), currentAddress, undefined, \"EVM\"];\n }\n\n if (looksLikeNearWallet(wallet)) {\n const accounts = await wallet.getAccounts();\n const { kwilSigner, publicKey } = await createNearWalletKwilSigner(\n wallet,\n accounts[0].accountId,\n store,\n kwilClient,\n );\n\n return [kwilSigner, accounts[0].accountId, publicKey, \"NEAR\"];\n }\n\n if (looksLikeXrpWallet(wallet)) {\n const { address: currentAddress, publicKey: walletPublicKey } = (await getXrpPublicKey(\n wallet,\n )) as { address: string; publicKey: string };\n if (!currentAddress) {\n throw new Error(\"Failed to get XRP address\");\n }\n\n return [\n await createXrpKwilSigner(wallet, currentAddress, store, kwilClient, walletPublicKey),\n currentAddress,\n walletPublicKey,\n \"XRPL\",\n ];\n }\n\n if (isCustomKwilSigner(wallet) || wallet instanceof FaceSignSignerProvider) {\n const storedAddress = await store.get<string>(\"signer-address\");\n\n if (storedAddress !== wallet.publicAddress) {\n store.set(\"signer-address\", wallet.publicAddress);\n try {\n await kwilClient.client.auth.logoutKGW();\n } catch (error) {\n console.log(\"error logoutKGW\", error);\n }\n }\n\n return [\n new KwilSigner(\n async (msg: Uint8Array) => wallet.signMessage(msg),\n wallet.publicAddress,\n \"ed25519\",\n ),\n wallet.publicAddress,\n wallet.publicKey,\n wallet.walletType as WalletType,\n ];\n }\n\n // Force the check that `signer` is `never`.\n // If these lines start complaining, that means we're missing an `if` above.\n return ((_: never) => {\n throw new Error(\"Invalid `signer` type\");\n })(wallet);\n}\n"],"mappings":";;;;;;;;;;;;AA2CA,IAAa,mBAAb,MAA8B;CAC5B;CACA;CAEA,YAAY,QAA4B;AACtC,OAAK,SAAS;;CAGhB,oBAAoB,YAAoB,SAAkC,EAAE,EAAoB;AAC9F,MAAI,CAAC,UAAU,CAAC,OAAO,KAAK,OAAO,CAAC,OAAQ,QAAO,EAAE;AAIrD,SAFc,aAAgE,YAElE,KAAK,EAAE,WAAW;GAC5B,MAAM,QAAQ,OAAO;AAErB,OAAI,UAAU,MAAM,UAAU,EAAG,QAAO;AACxC,UAAO,SAAS;IAChB;;CAGJ,aAAa,YAAgC;AAE3C,SADa,aAAa,YACd,KAAK,QAAQ,IAAI,KAAK;;;;;CAMpC,MAAM,KACJ,QACA,SAAiC,KAAK,QAC1B;EACZ,MAAM,SAAmB;GACvB,MAAM,OAAO;GACb,WAAW;GACX,QAAQ,MAAA,mBAAyB,OAAO,MAAM,OAAO,OAAO;GAC5D,OAAO,MAAA,YAAkB,OAAO,KAAK;G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O,eAAe;AAC1C,SAAM,IAAI,kBAAkB,OAAO,cAAc;AACjD,OAAI;AACF,UAAM,WAAW,OAAO,KAAK,WAAW;YACjC,OAAO;AACd,YAAQ,IAAI,mBAAmB,MAAM;;;AAIzC,SAAO;GACL,IAAIA,aACF,OAAO,QAAoB,OAAO,YAAY,IAAI,EAClD,OAAO,eACP,UACD;GACD,OAAO;GACP,OAAO;GACP,OAAO;GACR;;AAKH,UAAS,MAAa;AACpB,QAAM,IAAI,MAAM,wBAAwB;IACvC,OAAO"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["#createActionInputs","#actionTypes","KwilSigner","KwilSigner","KwilSigner"],"sources":["../src/create-kwil-client.ts","../src/near/get-config.ts","../src/near/create-near-wallet-kwil-signer.ts","../src/near/nep413.ts","../src/xrp/signer.ts","../src/create-kwil-signer.ts"],"sourcesContent":["import type { Config } from \"@idos-network/kwil-js/dist/api_client/config\";\nimport type {\n ActionBody,\n CallBody,\n PositionalParams,\n} from \"@idos-network/kwil-js/dist/core/action\";\nimport type { DataInfo } from \"@idos-network/kwil-js/dist/core/database\";\n\nimport { type KwilSigner, NodeKwil, WebKwil } from \"@idos-network/kwil-js\";\nimport invariant from \"tiny-invariant\";\n\nimport type { ActionSchemaElement } from \"./actions\";\n\nimport { actionSchema } from \"./actions\";\n\ntype CreateKwilClientParams = {\n chainId?: string;\n nodeUrl: string;\n};\n\ntype KwilActions = typeof actionSchema;\ntype ActionName = keyof KwilActions;\n\ntype AllKwilCallAction = {\n [Name in ActionName]: {\n name: Name;\n // oxlint-disable-next-line typescript/no-explicit-any -- This is fine\n inputs: Record<KwilActions[Name][number][\"name\"], any>;\n };\n};\n\ntype KwilCallActionRequestParams = AllKwilCallAction[ActionName];\n\ntype AllKwilExecuteAction = {\n [Name in ActionName]: AllKwilCallAction[Name] & { description: string };\n};\n\ntype KwilExecuteActionRequestParams = AllKwilExecuteAction[ActionName];\n\n/**\n * A client for interacting with kwil with type-safe abstractions for `call` and `execute`.\n * Has utility methods for creating actions and setting a signer.\n */\nexport class KwilActionClient {\n signer?: KwilSigner;\n readonly client: NodeKwil | WebKwil;\n\n constructor(client: NodeKwil | WebKwil) {\n this.client = client;\n }\n\n #createActionInputs(actionName: string, params: Record<string, unknown> = {}): PositionalParams {\n if (!params || !Object.keys(params).length) return [];\n\n const args = (actionSchema as Record<string, readonly ActionSchemaElement[]>)[actionName];\n\n return args.map(({ name }) => {\n const value = params[name];\n // Handle falsy values appropriately\n if (value === \"\" || value === 0) return value;\n return value ?? null;\n }) as PositionalParams;\n }\n\n #actionTypes(actionName: string): DataInfo[] {\n const args = actionSchema[actionName];\n return args.map((arg) => arg.type);\n }\n\n /**\n * Calls an action on the kwil nodes. This similar to `GET` like request.\n */\n async call<T = unknown>(\n params: KwilCallActionRequestParams,\n signer: KwilSigner | undefined = this.signer,\n ): Promise<T> {\n const action: CallBody = {\n name: params.name,\n namespace: \"main\",\n inputs: this.#createActionInputs(params.name, params.inputs),\n types: this.#actionTypes(params.name),\n };\n\n const response = await this.client.call(action as CallBody, signer);\n return response?.data?.result as T;\n }\n\n /**\n * Executes an action on the kwil nodes. This similar to `POST` like request.\n */\n async execute(\n params: KwilExecuteActionRequestParams,\n signer: KwilSigner | undefined = this.signer,\n synchronous = true,\n ): Promise<string | undefined> {\n invariant(signer, \"Signer is not set, you must set it before executing an action\");\n const action: ActionBody = {\n name: params.name,\n namespace: \"main\",\n description: params.description,\n inputs: [this.#createActionInputs(params.name, params.inputs)],\n types: this.#actionTypes(params.name),\n };\n const response = await this.client.execute(action, signer, synchronous);\n return response.data?.tx_hash;\n }\n\n setSigner(signer: KwilSigner | undefined): void {\n this.signer = signer;\n }\n\n /**\n * Creates action inputs from the given parameters that are used in the action body.\n */\n}\n\nconst DEFAULT_TIMEOUT = 30_000;\n\nconst createKwilClient =\n (Cls: new (opts: Config) => NodeKwil | WebKwil) =>\n async ({ nodeUrl: kwilProvider, chainId }: CreateKwilClientParams): Promise<KwilActionClient> => {\n const _kwil = new Cls({ kwilProvider, chainId: \"\" });\n // oxlint-disable-next-line no-param-reassign -- Default value fallback\n chainId ||= (await _kwil.chainInfo({ disableWarning: true })).data?.chain_id;\n invariant(chainId, \"Can't discover `chainId`. You must pass it explicitly.\");\n\n const client = new KwilActionClient(\n new Cls({ kwilProvider, chainId, timeout: DEFAULT_TIMEOUT }),\n );\n\n return client;\n };\n\n/**\n * Create a kwil client for node.js environment\n */\nexport const createNodeKwilClient: (params: CreateKwilClientParams) => Promise<KwilActionClient> =\n createKwilClient(NodeKwil);\n\n/**\n * Create a kwil client for browser environment\n */\nexport const createWebKwilClient: (params: CreateKwilClientParams) => Promise<KwilActionClient> =\n createKwilClient(WebKwil);\n","// Network configuration mapping\nconst NEAR_NETWORKS = {\n mainnet: {\n networkId: \"mainnet\",\n nodeUrl: \"https://rpc.mainnet.near.org\",\n },\n testnet: {\n networkId: \"testnet\",\n nodeUrl: \"https://rpc.testnet.near.org\",\n },\n betanet: {\n networkId: \"betanet\",\n nodeUrl: \"https://rpc.betanet.near.org\",\n },\n shardnet: {\n networkId: \"shardnet\",\n nodeUrl: \"https://rpc.shardnet.near.org\",\n },\n} as const;\n\n// Function to detect NEAR network from account ID\nexport const detectNearNetwork = (accountId: string): keyof typeof NEAR_NETWORKS => {\n if (accountId.endsWith(\".near\")) return \"mainnet\";\n if (accountId.endsWith(\".testnet\")) return \"testnet\";\n if (accountId.endsWith(\".betanet\")) return \"betanet\";\n if (accountId.endsWith(\".shardnet\")) return \"shardnet\";\n\n // Default to testnet for development, mainnet for production\n return \"testnet\";\n};\n\n// Function to get connection config based on account ID\nexport const getNearConnectionConfig = (\n accountId: string,\n): { networkId: string; nodeUrl: string } => {\n const network = detectNearNetwork(accountId);\n const networkConfig = NEAR_NETWORKS[network];\n\n return {\n networkId: networkConfig.networkId,\n nodeUrl: networkConfig.nodeUrl,\n };\n};\n","import type { Store } from \"@idos-network/utils/store\";\nimport type {\n Wallet as NearWallet,\n SignedMessage,\n SignMessageParams,\n} from \"@near-wallet-selector/core\";\nimport type { connect as connectT } from \"near-api-js\";\nimport type { AccessKeyList } from \"near-api-js/lib/providers/provider\";\n\nimport { KwilSigner } from \"@idos-network/kwil-js\";\nimport {\n base64Decode,\n binaryWriteUint16BE,\n borshSerialize,\n bs58Decode,\n bytesConcat,\n hexEncode,\n utf8Decode,\n} from \"@idos-network/utils/codecs\";\n\nimport type { KwilActionClient } from \"../create-kwil-client\";\n\nimport { getNearConnectionConfig } from \"./get-config\";\n\nconst NEAR_WALLET_TYPES: string[] = [\n \"browser\",\n \"injected\",\n \"instant-link\",\n \"hardware\",\n \"bridge\",\n] satisfies NearWallet[\"type\"][];\n\nexport function looksLikeNearWallet(signer: unknown): signer is NearWallet {\n return (\n signer !== null &&\n typeof signer === \"object\" &&\n \"id\" in signer &&\n \"metadata\" in signer &&\n \"type\" in signer &&\n typeof signer.type === \"string\" &&\n NEAR_WALLET_TYPES.includes(signer.type)\n );\n}\n\nclass KwilNonce {\n bytes: Uint8Array;\n\n constructor(length = 32) {\n // We're in the browser, so there's a window.crypto for sure.\n /* global crypto */\n this.bytes = crypto.getRandomValues(new Uint8Array(length));\n }\n\n get clampUTF8() {\n return this.bytes.map((byte) => byte & 127);\n }\n}\n\n/**\n * Creates a signer function that can be used to sign messages with a NEAR wallet\n */\nfunction createNearWalletSigner(\n wallet: NearWallet,\n recipient: string,\n): (message: string | Uint8Array) => Promise<Uint8Array> {\n return async (message: string | Uint8Array): Promise<Uint8Array> => {\n const messageString = typeof message === \"string\" ? message : utf8Decode(message);\n\n if (!wallet.signMessage) {\n throw new Error(\"Only wallets with signMessage are supported.\");\n }\n\n const nonceSuggestion = Buffer.from(new KwilNonce(32).bytes);\n\n const {\n nonce = nonceSuggestion,\n signature,\n // @ts-expect-error Signatures don't seem to be updated for NEP413 yet.\n callbackUrl,\n // oxlint-disable-next-line typescript/no-non-null-assertion -- Only non-signing wallets return void.\n } = (await (\n wallet.signMessage as (\n _: SignMessageParams,\n ) => Promise<SignedMessage & { nonce?: Uint8Array }>\n )({\n message: messageString,\n recipient,\n nonce: nonceSuggestion,\n }))!;\n\n const nep413BorschSchema = {\n struct: {\n tag: \"u32\",\n message: \"string\",\n nonce: { array: { type: \"u8\", len: 32 } },\n recipient: \"string\",\n callbackUrl: { option: \"string\" },\n },\n };\n\n const nep413BorshParams = {\n tag: 2147484061,\n message: messageString,\n nonce: Array.from(nonce),\n recipient,\n callbackUrl,\n };\n\n const nep413BorshPayload = borshSerialize(nep413BorschSchema, nep413BorshParams);\n const result = bytesConcat(\n binaryWriteUint16BE(nep413BorshPayload.length),\n nep413BorshPayload,\n base64Decode(signature),\n );\n\n return result;\n };\n}\n\nexport function implicitAddressFromPublicKey(publicKey: string): string {\n const key_without_prefix = publicKey.replace(/^ed25519:/, \"\");\n return hexEncode(bs58Decode(key_without_prefix));\n}\n\nexport async function getNearFullAccessPublicKeys(\n namedAddress: string,\n): Promise<string[] | undefined> {\n let connect: typeof connectT;\n try {\n connect = (await import(\"near-api-js\")).connect;\n } catch (_e) {\n throw new Error(\"Can't load near-api-js\");\n }\n const connectionConfig = getNearConnectionConfig(namedAddress);\n const nearConnection = await connect(connectionConfig);\n\n try {\n const response: AccessKeyList = await nearConnection.connection.provider.query({\n request_type: \"view_access_key_list\",\n finality: \"final\",\n account_id: namedAddress,\n });\n return response.keys\n .filter((element) => element.access_key.permission === \"FullAccess\")\n ?.map((i) => i.public_key);\n } catch {\n // `Near` failed if namedAddress contains uppercase symbols\n return;\n }\n}\n\nexport async function signNearMessage(\n wallet: NearWallet,\n message: string,\n recipient = \"idos.network\",\n): Promise<string> {\n const signer = createNearWalletSigner(wallet, recipient);\n const signedPayload = await signer(message);\n return hexEncode(signedPayload);\n}\n\nexport async function createNearWalletKwilSigner(\n wallet: NearWallet,\n currentAddress: string,\n store: Store,\n kwilClient: KwilActionClient,\n recipient = \"idos.network\",\n): Promise<{ kwilSigner: KwilSigner; publicKey: string }> {\n if (!wallet.signMessage) throw new Error(\"Only wallets with signMessage are supported.\");\n\n if (wallet.id === \"my-near-wallet\") {\n const { accountId, signature, publicKey, error } = Object.fromEntries(\n new URLSearchParams(window.location.hash.slice(1)).entries(),\n );\n\n if (signature) {\n await store.set(\"signer-address\", accountId);\n await store.set(\"signer-public-key\", publicKey);\n }\n\n const signMessageOriginal = wallet.signMessage.bind(wallet);\n\n wallet.signMessage = async ({\n message,\n recipient,\n }: SignMessageParams): Promise<SignedMessage & { nonce?: Uint8Array }> => {\n if (error) return Promise.reject();\n\n const lastMessage = await store.get<string>(\"sign-last-message\");\n const lastNonce = await store.get<Uint8Array>(\"sign-last-nonce\");\n\n if (signature && message === lastMessage && lastNonce) {\n const nonce = Buffer.from(lastNonce);\n const callbackUrl = await store.get<string>(\"sign-last-url\");\n\n return Promise.resolve({\n accountId: currentAddress,\n publicKey,\n signature,\n nonce,\n message,\n callbackUrl,\n } as SignedMessage);\n }\n\n const callbackUrl = window.location.href;\n const nonce = Buffer.from(new KwilNonce(32).clampUTF8);\n\n await store.set(\"sign-last-message\", message);\n await store.set(\"sign-last-nonce\", Array.from(nonce));\n await store.set(\"sign-last-url\", callbackUrl);\n\n signMessageOriginal({ message, nonce, recipient, callbackUrl });\n\n return new Promise(() => ({}) as SignedMessage);\n };\n }\n\n const storedAddress = await store.get<string>(\"signer-address\");\n\n let publicKey = await store.get<string>(\"signer-public-key\");\n\n if (storedAddress !== currentAddress || !publicKey) {\n store.reset();\n // To avoid re-using the old signer's kgw cookie.\n // When kwil-js supports multi cookies, we can remove this.\n await kwilClient.client.auth.logoutKGW();\n\n const message = \"idOS authentication\";\n const nonce = Buffer.from(new KwilNonce(32).bytes);\n const signResult = await wallet.signMessage({ message, recipient, nonce });\n if (!signResult) throw new Error(\"signMessage returned no result\");\n ({ publicKey } = signResult);\n\n await store.set(\"signer-address\", currentAddress);\n await store.set(\"signer-public-key\", publicKey);\n }\n\n const signer = createNearWalletSigner(wallet, recipient);\n\n return {\n kwilSigner: new KwilSigner(signer, implicitAddressFromPublicKey(publicKey), \"nep413\"),\n publicKey,\n };\n}\n","import type { KeyPair } from \"near-api-js\";\n\nimport {\n binaryWriteUint16BE,\n borshSerialize,\n bytesConcat,\n sha256Hash,\n utf8Decode,\n} from \"@idos-network/utils/codecs\";\n\nexport function kwilNep413Signer(\n recipient: string,\n): (keyPair: KeyPair) => (messageBytes: Uint8Array) => Promise<Uint8Array> {\n return (keyPair: KeyPair) =>\n async (messageBytes: Uint8Array): Promise<Uint8Array> => {\n const message = utf8Decode(messageBytes);\n const nonceLength = 32;\n const nonce = crypto.getRandomValues(new Uint8Array(nonceLength));\n\n const nep413BorschSchema = {\n struct: {\n message: \"string\",\n nonce: { array: { type: \"u8\", len: nonceLength } },\n recipient: \"string\",\n callbackUrl: { option: \"string\" },\n },\n } as const;\n\n const tag = 2147484061; // 2**31 + 413\n\n const { signature } = keyPair.sign(\n sha256Hash(\n bytesConcat(\n borshSerialize(\"u32\", tag),\n borshSerialize(nep413BorschSchema, { message, nonce, recipient }),\n ),\n ),\n );\n\n const kwilNep413BorschSchema = {\n struct: {\n tag: \"u32\",\n ...nep413BorschSchema.struct,\n },\n };\n\n const kwilNep413BorshParams = {\n tag,\n message,\n nonce,\n recipient,\n };\n\n const kwilNep413BorshPayload = borshSerialize(kwilNep413BorschSchema, kwilNep413BorshParams);\n\n return bytesConcat(\n binaryWriteUint16BE(kwilNep413BorshPayload.length),\n kwilNep413BorshPayload,\n signature,\n );\n };\n}\n","import type * as GemWallet from \"@gemwallet/api\";\nimport type { Store } from \"@idos-network/utils/store\";\nimport type { Xumm } from \"xumm\";\n\nimport { KwilSigner } from \"@idos-network/kwil-js\";\n\nimport type { KwilActionClient } from \"../create-kwil-client\";\n\nimport { getXrpTxHash } from \"./utils\";\n\nexport async function createXrpKwilSigner(\n wallet: Xumm | typeof GemWallet,\n currentAddress: string,\n store: Store,\n kwilClient: KwilActionClient,\n walletPublicKey: string,\n): Promise<KwilSigner> {\n const storedAddress = await store.get<string>(\"signer-address\");\n const storePublicKey = await store.get<string>(\"signer-public-key\");\n\n if (storedAddress !== currentAddress || (storePublicKey && storePublicKey !== walletPublicKey)) {\n try {\n // HEADS UP: for some reason logoutKGW fails on xrp\n // storePublicKey && await kwilClient.client.auth.logoutKGW();\n console.log(\"logoutKGW\", kwilClient);\n } catch (error) {\n console.error(\"Failed to logout KGW:\", error);\n }\n }\n\n await store.set(\"signer-address\", currentAddress);\n await store.set(\"signer-public-key\", walletPublicKey);\n\n const signer = async (message: string | Uint8Array): Promise<Uint8Array> => {\n const signature = await getXrpTxHash(message, wallet);\n if (!signature) {\n throw new Error(\"Failed to sign transaction with XRP\");\n }\n return Buffer.from(signature, \"hex\");\n };\n\n return new KwilSigner(signer, walletPublicKey, \"xrpl\");\n}\n","import type { Store } from \"@idos-network/utils/store\";\nimport type { Wallet as NearWallet } from \"@near-wallet-selector/core\";\nimport type { Keypair as StellarKeypair } from \"@stellar/stellar-sdk\";\nimport type { Wallet as EthersWallet, JsonRpcSigner } from \"ethers\";\nimport type { KeyPair as NearKeyPair } from \"near-api-js\";\nimport type { KeyPair as XrpKeyPair } from \"ripple-keypairs/src/types\";\n\nimport { KwilSigner } from \"@idos-network/kwil-js\";\nimport { bs58Encode, hexDecode, hexEncode } from \"@idos-network/utils/codecs\";\nimport nacl from \"tweetnacl\";\n\nimport type { WalletType } from \"./actions\";\nimport type { KwilActionClient } from \"./create-kwil-client\";\n\nimport { FaceSignSignerProvider } from \"./facesign/facesign-signer\";\nimport {\n createNearWalletKwilSigner,\n implicitAddressFromPublicKey,\n looksLikeNearWallet,\n} from \"./near/create-near-wallet-kwil-signer\";\nimport { kwilNep413Signer } from \"./near/nep413\";\nimport { createXrpKwilSigner } from \"./xrp/signer\";\nimport { getXrpPublicKey, looksLikeXrpWallet } from \"./xrp/utils\";\n\nexport { KwilSigner } from \"@idos-network/kwil-js\";\nexport type Wallet =\n | EthersWallet\n | JsonRpcSigner\n | NearWallet\n | CustomKwilSigner\n | FaceSignSignerProvider;\n\n/**\n * Helper function to check if the given object is a `nacl.SignKeyPair`.\n */\nfunction isNaclSignKeyPair(object: unknown): object is nacl.SignKeyPair {\n return (\n object !== null &&\n typeof object === \"object\" &&\n \"publicKey\" in object &&\n object.publicKey instanceof Uint8Array &&\n object.publicKey.length === nacl.sign.publicKeyLength &&\n \"secretKey\" in object &&\n object.secretKey instanceof Uint8Array &&\n object.secretKey.length === nacl.sign.secretKeyLength\n );\n}\n\n/**\n * Helper function to check if the given object is a NEAR KeyPair.\n */\nfunction isNearKeyPair(object: unknown): object is NearKeyPair {\n return (\n object !== null &&\n typeof object === \"object\" &&\n \"getPublicKey\" in object &&\n \"sign\" in object &&\n typeof object.getPublicKey === \"function\" &&\n typeof object.sign === \"function\"\n );\n}\n\n/**\n * Helper function to check if the given object is a Stellar Keypair.\n */\nfunction isStellarKeyPair(object: unknown): object is StellarKeypair {\n return (\n object !== null &&\n typeof object === \"object\" &&\n \"publicKey\" in object &&\n \"sign\" in object &&\n \"canSign\" in object &&\n typeof object.publicKey === \"function\" &&\n typeof object.sign === \"function\" &&\n typeof object.canSign === \"function\"\n );\n}\n\nexport interface CustomKwilSigner extends KwilSigner {\n publicAddress: string;\n signatureType: string;\n publicKey: string;\n walletType: string;\n signMessage: (message: Uint8Array | string) => Promise<Uint8Array>;\n}\n\nfunction isCustomKwilSigner(object: unknown): object is CustomKwilSigner {\n return (\n object !== null &&\n typeof object === \"object\" &&\n \"publicAddress\" in object &&\n \"signatureType\" in object &&\n \"publicKey\" in object &&\n \"signMessage\" in object\n );\n}\n\n/**\n * Helper function to check if the given object is a XRP KeyPair (Server key pairs only).\n */\nfunction isXrplKeyPair(object: unknown): object is XrpKeyPair {\n return !!object && typeof object === \"object\" && \"privateKey\" in object && \"publicKey\" in object;\n}\n\nexport type KwilSignerType =\n | NearKeyPair\n | EthersWallet\n | nacl.SignKeyPair\n | JsonRpcSigner\n | StellarKeypair\n | XrpKeyPair;\n\nexport type SignerAddress = string;\nexport type SignerPublicKey = string | undefined;\n\n/**\n * Creates a `KwilSigner` and its associated `SignerAddress`.\n *\n * This function is explicitly marked as being for backend use only because it doesn't reset\n * the KGW cookie when logging out and re-logging in with a different wallet.\n */\nexport async function createServerKwilSigner(\n signer: KwilSignerType,\n): Promise<[KwilSigner, SignerAddress]> {\n if (isNaclSignKeyPair(signer)) {\n return [\n new KwilSigner(\n async (msg: Uint8Array) => nacl.sign.detached(msg, signer.secretKey),\n signer.publicKey,\n \"ed25519\",\n ),\n implicitAddressFromPublicKey(bs58Encode(signer.publicKey)),\n ];\n }\n\n if (isNearKeyPair(signer)) {\n const publicKey = implicitAddressFromPublicKey(signer.getPublicKey().toString());\n return [\n new KwilSigner(kwilNep413Signer(\"idos-issuer\")(signer), publicKey, \"nep413\"),\n publicKey,\n ];\n }\n\n if (isStellarKeyPair(signer)) {\n const publicKeyString = signer.publicKey();\n const rawPublicKey = signer.rawPublicKey();\n return [\n new KwilSigner(\n async (msg: Uint8Array) => signer.sign(Buffer.from(msg)),\n rawPublicKey,\n \"ed25519\",\n ),\n publicKeyString,\n ];\n }\n\n if (isXrplKeyPair(signer)) {\n let xrpKeypair: typeof import(\"ripple-keypairs\");\n\n try {\n xrpKeypair = await import(\"ripple-keypairs\");\n } catch (e) {\n throw new Error(\"Can't load ripple-keypairs\", { cause: e });\n }\n\n return [\n new KwilSigner(\n async (msg: Uint8Array) => hexDecode(xrpKeypair.sign(hexEncode(msg), signer.privateKey)),\n signer.publicKey,\n \"xrpl\",\n ),\n signer.publicKey,\n ];\n }\n\n if (\"address\" in signer) {\n return [new KwilSigner(signer, signer.address), signer.address];\n }\n\n // Force the check that `signer` is never.\n // If these lines start complaining, that means we're missing an `if` above.\n return ((_: never) => {\n throw new Error(\"Invalid `signer` type\");\n })(signer);\n}\n\nexport async function createClientKwilSigner(\n store: Store,\n kwilClient: KwilActionClient,\n wallet: Wallet,\n): Promise<[KwilSigner, SignerAddress, SignerPublicKey, WalletType]> {\n if (\"connect\" in wallet && \"address\" in wallet) {\n // oxlint-disable-next-line no-param-reassign -- Narrowing the type on purpose\n wallet = wallet as unknown as JsonRpcSigner;\n const currentAddress = await wallet.getAddress();\n\n const storedAddress = await store.get<string>(\"signer-address\");\n\n if (storedAddress !== currentAddress) {\n // To avoid re-using the old signer's kgw cookie.\n // When kwil-js supports multi cookies, we can remove this.\n store.set(\"signer-address\", currentAddress);\n try {\n await kwilClient.client.auth.logoutKGW();\n } catch (error) {\n console.log(\"error logoutKGW\", error);\n }\n }\n\n return [new KwilSigner(wallet, currentAddress), currentAddress, undefined, \"EVM\"];\n }\n\n if (looksLikeNearWallet(wallet)) {\n const accounts = await wallet.getAccounts();\n const { kwilSigner, publicKey } = await createNearWalletKwilSigner(\n wallet,\n accounts[0].accountId,\n store,\n kwilClient,\n );\n\n return [kwilSigner, accounts[0].accountId, publicKey, \"NEAR\"];\n }\n\n if (looksLikeXrpWallet(wallet)) {\n const { address: currentAddress, publicKey: walletPublicKey } = (await getXrpPublicKey(\n wallet,\n )) as { address: string; publicKey: string };\n if (!currentAddress) {\n throw new Error(\"Failed to get XRP address\");\n }\n\n return [\n await createXrpKwilSigner(wallet, currentAddress, store, kwilClient, walletPublicKey),\n currentAddress,\n walletPublicKey,\n \"XRPL\",\n ];\n }\n\n if (isCustomKwilSigner(wallet) || wallet instanceof FaceSignSignerProvider) {\n const storedAddress = await store.get<string>(\"signer-address\");\n\n if (storedAddress !== wallet.publicAddress) {\n store.set(\"signer-address\", wallet.publicAddress);\n try {\n await kwilClient.client.auth.logoutKGW();\n } catch (error) {\n console.log(\"error logoutKGW\", error);\n }\n }\n\n return [\n new KwilSigner(\n async (msg: Uint8Array) => wallet.signMessage(msg),\n wallet.publicAddress,\n \"ed25519\",\n ),\n wallet.publicAddress,\n wallet.publicKey,\n wallet.walletType as WalletType,\n ];\n }\n\n // Force the check that `signer` is `never`.\n // If these lines start complaining, that means we're missing an `if` above.\n return ((_: never) => {\n throw new Error(\"Invalid `signer` type\");\n })(wallet);\n}\n"],"mappings":";;;;;;;;;;;;AA2CA,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IA,SAAS,MAAa;EACpB,MAAM,IAAI,MAAM,uBAAuB;CACzC,EAAA,CAAG,MAAM;AACX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/signature-verification/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/signature-verification/index.ts"],"mappings":";;UAUiB;EACf;EACA;EACA;EACA,aAAa;EACb;;cAGW,kBAAyB,eAAe,oBAAkB"}
|
|
@@ -61,27 +61,22 @@ const verifyRippleSignature = async (message, signature, publicKey) => {
|
|
|
61
61
|
//#endregion
|
|
62
62
|
//#region src/signature-verification/evm.ts
|
|
63
63
|
const verifyEvmSignature = async (message, signature, address) => {
|
|
64
|
-
let
|
|
64
|
+
let verifyMessage;
|
|
65
65
|
try {
|
|
66
|
-
|
|
66
|
+
verifyMessage = (await import("viem")).verifyMessage;
|
|
67
67
|
} catch (_e) {
|
|
68
|
-
throw new Error("Can't load
|
|
68
|
+
throw new Error("Can't load viem");
|
|
69
69
|
}
|
|
70
|
-
let chains;
|
|
71
70
|
try {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
return await verifyMessage({
|
|
72
|
+
address,
|
|
73
|
+
message,
|
|
74
|
+
signature
|
|
75
|
+
});
|
|
76
|
+
} catch (e) {
|
|
77
|
+
console.warn("EVM signature verification failed:", e);
|
|
78
|
+
return false;
|
|
75
79
|
}
|
|
76
|
-
const wagmiConfig = wagmi.createConfig({
|
|
77
|
-
chains: [chains.mainnet],
|
|
78
|
-
transports: { [chains.mainnet.id]: wagmi.http() }
|
|
79
|
-
});
|
|
80
|
-
return wagmi.verifyMessage(wagmiConfig, {
|
|
81
|
-
address,
|
|
82
|
-
message,
|
|
83
|
-
signature
|
|
84
|
-
});
|
|
85
80
|
};
|
|
86
81
|
//#endregion
|
|
87
82
|
//#region src/signature-verification/facesign.ts
|