@mysten/zksend 0.12.24 → 0.12.25
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 +6 -0
- package/dist/cjs/wallet/channel/events.d.ts +1 -1
- package/dist/cjs/wallet/channel/events.js +1 -1
- package/dist/cjs/wallet/channel/events.js.map +2 -2
- package/dist/cjs/wallet/channel/index.js +1 -1
- package/dist/cjs/wallet/channel/index.js.map +1 -1
- package/dist/esm/wallet/channel/events.d.ts +1 -1
- package/dist/esm/wallet/channel/events.js +1 -1
- package/dist/esm/wallet/channel/events.js.map +2 -2
- package/dist/esm/wallet/channel/index.js +1 -1
- package/dist/esm/wallet/channel/index.js.map +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -61,7 +61,7 @@ export declare const StashedResponsePayload: import("valibot").VariantSchema<"ty
|
|
|
61
61
|
export type StashedResponsePayload = InferOutput<typeof StashedResponsePayload>;
|
|
62
62
|
export declare const StashedResponse: import("valibot").ObjectSchema<{
|
|
63
63
|
readonly id: import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").UuidAction<string, undefined>]>;
|
|
64
|
-
readonly source: import("valibot").LiteralSchema<"
|
|
64
|
+
readonly source: import("valibot").LiteralSchema<"zksend-channel", undefined>;
|
|
65
65
|
readonly payload: import("valibot").VariantSchema<"type", [import("valibot").ObjectSchema<{
|
|
66
66
|
readonly type: import("valibot").LiteralSchema<"reject", undefined>;
|
|
67
67
|
}, undefined>, import("valibot").ObjectSchema<{
|
|
@@ -74,7 +74,7 @@ const StashedResponsePayload = (0, import_valibot.variant)("type", [
|
|
|
74
74
|
]);
|
|
75
75
|
const StashedResponse = (0, import_valibot.object)({
|
|
76
76
|
id: (0, import_valibot.pipe)((0, import_valibot.string)(), (0, import_valibot.uuid)()),
|
|
77
|
-
source: (0, import_valibot.literal)("
|
|
77
|
+
source: (0, import_valibot.literal)("zksend-channel"),
|
|
78
78
|
payload: StashedResponsePayload
|
|
79
79
|
});
|
|
80
80
|
//# sourceMappingURL=events.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/wallet/channel/events.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { InferOutput } from 'valibot';\nimport { literal, object, optional, pipe, string, url, uuid, variant } from 'valibot';\n\nexport const StashedRequestData = variant('type', [\n\tobject({\n\t\ttype: literal('connect'),\n\t}),\n\tobject({\n\t\ttype: literal('sign-transaction-block'),\n\t\tdata: string('`data` is required'),\n\t\taddress: string('`address` is required'),\n\t}),\n\tobject({\n\t\ttype: literal('sign-personal-message'),\n\t\tbytes: string('`bytes` is required'),\n\t\taddress: string('`address` is required'),\n\t}),\n]);\nexport type StashedRequestData = InferOutput<typeof StashedRequestData>;\n\nexport const StashedRequest = object({\n\tid: pipe(string('`id` is required'), uuid()),\n\torigin: pipe(string(), url('`origin` must be a valid URL')),\n\tname: optional(string()),\n\tpayload: StashedRequestData,\n});\n\nexport type StashedRequest = InferOutput<typeof StashedRequest>;\n\nexport const StashedResponseData = variant('type', [\n\tobject({\n\t\ttype: literal('connect'),\n\t\taddress: string(),\n\t}),\n\tobject({\n\t\ttype: literal('sign-transaction-block'),\n\t\tbytes: string(),\n\t\tsignature: string(),\n\t}),\n\tobject({\n\t\ttype: literal('sign-personal-message'),\n\t\tbytes: string(),\n\t\tsignature: string(),\n\t}),\n]);\nexport type StashedResponseData = InferOutput<typeof StashedResponseData>;\n\nexport const StashedResponsePayload = variant('type', [\n\tobject({\n\t\ttype: literal('reject'),\n\t}),\n\tobject({\n\t\ttype: literal('resolve'),\n\t\tdata: StashedResponseData,\n\t}),\n]);\nexport type StashedResponsePayload = InferOutput<typeof StashedResponseP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AQ,QAAQ;AAAA,EACvB,CAAC;AAAA,MACD,uBAAO;AAAA,IACN,UAAM,wBAAQ,SAAS;AAAA,IACvB,MAAM;AAAA,EACP,CAAC;AACF,CAAC;AAGM,MAAM,sBAAkB,uBAAO;AAAA,EACrC,QAAI,yBAAK,uBAAO,OAAG,qBAAK,CAAC;AAAA,EACzB,YAAQ,wBAAQ,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { InferOutput } from 'valibot';\nimport { literal, object, optional, pipe, string, url, uuid, variant } from 'valibot';\n\nexport const StashedRequestData = variant('type', [\n\tobject({\n\t\ttype: literal('connect'),\n\t}),\n\tobject({\n\t\ttype: literal('sign-transaction-block'),\n\t\tdata: string('`data` is required'),\n\t\taddress: string('`address` is required'),\n\t}),\n\tobject({\n\t\ttype: literal('sign-personal-message'),\n\t\tbytes: string('`bytes` is required'),\n\t\taddress: string('`address` is required'),\n\t}),\n]);\nexport type StashedRequestData = InferOutput<typeof StashedRequestData>;\n\nexport const StashedRequest = object({\n\tid: pipe(string('`id` is required'), uuid()),\n\torigin: pipe(string(), url('`origin` must be a valid URL')),\n\tname: optional(string()),\n\tpayload: StashedRequestData,\n});\n\nexport type StashedRequest = InferOutput<typeof StashedRequest>;\n\nexport const StashedResponseData = variant('type', [\n\tobject({\n\t\ttype: literal('connect'),\n\t\taddress: string(),\n\t}),\n\tobject({\n\t\ttype: literal('sign-transaction-block'),\n\t\tbytes: string(),\n\t\tsignature: string(),\n\t}),\n\tobject({\n\t\ttype: literal('sign-personal-message'),\n\t\tbytes: string(),\n\t\tsignature: string(),\n\t}),\n]);\nexport type StashedResponseData = InferOutput<typeof StashedResponseData>;\n\nexport const StashedResponsePayload = variant('type', [\n\tobject({\n\t\ttype: literal('reject'),\n\t}),\n\tobject({\n\t\ttype: literal('resolve'),\n\t\tdata: StashedResponseData,\n\t}),\n]);\nexport type StashedResponsePayload = InferOutput<typeof StashedResponsePayload>;\n\nexport const StashedResponse = object({\n\tid: pipe(string(), uuid()),\n\tsource: literal('zksend-channel'),\n\tpayload: StashedResponsePayload,\n});\nexport type StashedResponse = InferOutput<typeof StashedResponse>;\n\nexport type StashedRequestTypes = Record<string, any> & {\n\t[P in StashedRequestData as P['type']]: P;\n};\n\nexport type StashedResponseTypes = {\n\t[P in StashedResponseData as P['type']]: P;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,qBAA4E;AAErE,MAAM,yBAAqB,wBAAQ,QAAQ;AAAA,MACjD,uBAAO;AAAA,IACN,UAAM,wBAAQ,SAAS;AAAA,EACxB,CAAC;AAAA,MACD,uBAAO;AAAA,IACN,UAAM,wBAAQ,wBAAwB;AAAA,IACtC,UAAM,uBAAO,oBAAoB;AAAA,IACjC,aAAS,uBAAO,uBAAuB;AAAA,EACxC,CAAC;AAAA,MACD,uBAAO;AAAA,IACN,UAAM,wBAAQ,uBAAuB;AAAA,IACrC,WAAO,uBAAO,qBAAqB;AAAA,IACnC,aAAS,uBAAO,uBAAuB;AAAA,EACxC,CAAC;AACF,CAAC;AAGM,MAAM,qBAAiB,uBAAO;AAAA,EACpC,QAAI,yBAAK,uBAAO,kBAAkB,OAAG,qBAAK,CAAC;AAAA,EAC3C,YAAQ,yBAAK,uBAAO,OAAG,oBAAI,8BAA8B,CAAC;AAAA,EAC1D,UAAM,6BAAS,uBAAO,CAAC;AAAA,EACvB,SAAS;AACV,CAAC;AAIM,MAAM,0BAAsB,wBAAQ,QAAQ;AAAA,MAClD,uBAAO;AAAA,IACN,UAAM,wBAAQ,SAAS;AAAA,IACvB,aAAS,uBAAO;AAAA,EACjB,CAAC;AAAA,MACD,uBAAO;AAAA,IACN,UAAM,wBAAQ,wBAAwB;AAAA,IACtC,WAAO,uBAAO;AAAA,IACd,eAAW,uBAAO;AAAA,EACnB,CAAC;AAAA,MACD,uBAAO;AAAA,IACN,UAAM,wBAAQ,uBAAuB;AAAA,IACrC,WAAO,uBAAO;AAAA,IACd,eAAW,uBAAO;AAAA,EACnB,CAAC;AACF,CAAC;AAGM,MAAM,6BAAyB,wBAAQ,QAAQ;AAAA,MACrD,uBAAO;AAAA,IACN,UAAM,wBAAQ,QAAQ;AAAA,EACvB,CAAC;AAAA,MACD,uBAAO;AAAA,IACN,UAAM,wBAAQ,SAAS;AAAA,IACvB,MAAM;AAAA,EACP,CAAC;AACF,CAAC;AAGM,MAAM,sBAAkB,uBAAO;AAAA,EACrC,QAAI,yBAAK,uBAAO,OAAG,qBAAK,CAAC;AAAA,EACzB,YAAQ,wBAAQ,gBAAgB;AAAA,EAChC,SAAS;AACV,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/wallet/channel/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { InferOutput } from 'valibot';\nimport { parse, safeParse } from 'valibot';\n\nimport { withResolvers } from '../../utils/withResolvers.js';\nimport type { StashedSupportedNetwork } from '../types.js';\nimport type { StashedRequestData, StashedResponsePayload, StashedResponseTypes } from './events.js';\nimport { StashedRequest, StashedResponse } from './events.js';\n\nexport const DEFAULT_STASHED_ORIGIN = 'https://getstashed.com';\n\nexport { StashedRequest, StashedResponse };\n\nexport class StashedPopup {\n\t#popup: Window;\n\n\t#id: string;\n\t#origin: string;\n\t#name: string;\n\t#network: StashedSupportedNetwork;\n\n\t#promise: Promise<unknown>;\n\t#resolve: (data: unknown) => void;\n\t#reject: (error: Error) => void;\n\n\t#interval: ReturnType<typeof setInterval> | null = null;\n\n\tconstructor({\n\t\tname,\n\t\tnetwork,\n\t\torigin = DEFAULT_STASHED_ORIGIN,\n\t}: {\n\t\tname: string;\n\t\tnetwork: StashedSupportedNetwork;\n\t\torigin?: string;\n\t}) {\n\t\tconst popup = window.open('about:blank', '_blank');\n\n\t\tif (!popup) {\n\t\t\tthrow new Error('Failed to open new window');\n\t\t}\n\t\tthis.#popup = popup;\n\n\t\tthis.#id = crypto.randomUUID();\n\t\tthis.#origin = origin;\n\t\tthis.#name = name;\n\t\tthis.#network = network;\n\n\t\tconst { promise, resolve, reject } = withResolvers();\n\t\tthis.#promise = promise;\n\t\tthis.#resolve = resolve;\n\t\tthis.#reject = reject;\n\n\t\tthis.#interval = setInterval(() => {\n\t\t\ttry {\n\t\t\t\tif (this.#popup.closed) {\n\t\t\t\t\tthis.#cleanup();\n\t\t\t\t\treject(new Error('User closed the Stashed window'));\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// This can error during the login flow, but that's fine.\n\t\t\t}\n\t\t}, 1000);\n\t}\n\n\tsend<T extends StashedRequestData['type']>({\n\t\ttype,\n\t\t...data\n\t}: {\n\t\ttype: T;\n\t} & Extract<StashedRequestData, { type: T }>): Promise<StashedResponseTypes[T]> {\n\t\twindow.addEventListener('message', this.#listener);\n\t\tthis.#popup.location.assign(\n\t\t\t`${this.#origin}/dapp/${type}?${new URLSearchParams({\n\t\t\t\tid: this.#id,\n\t\t\t\torigin: window.origin,\n\t\t\t\tnetwork: this.#network,\n\t\t\t\tname: this.#name,\n\t\t\t})}${data ? `#${new URLSearchParams(data as never)}` : ''}`,\n\t\t);\n\n\t\treturn this.#promise as Promise<StashedResponseTypes[T]>;\n\t}\n\n\tclose() {\n\t\tthis.#cleanup();\n\t\tthis.#popup.close();\n\t}\n\n\t#listener = (event: MessageEvent) => {\n\t\tif (event.origin !== this.#origin) {\n\t\t\treturn;\n\t\t}\n\t\tconst { success, output } = safeParse(StashedResponse, event.data);\n\t\tif (!success || output.id !== this.#id) return;\n\n\t\tthis.#cleanup();\n\n\t\tif (output.payload.type === 'reject') {\n\t\t\tthis.#reject(new Error('User rejected the request'));\n\t\t} else if (output.payload.type === 'resolve') {\n\t\t\tthis.#resolve(output.payload.data);\n\t\t}\n\t};\n\n\t#cleanup() {\n\t\tif (this.#interval) {\n\t\t\tclearInterval(this.#interval);\n\t\t\tthis.#interval = null;\n\t\t}\n\t\twindow.removeEventListener('message', this.#listener);\n\t}\n}\n\nexport class StashedHost {\n\t#request: InferOutput<typeof StashedRequest>;\n\n\tconstructor(request: InferOutput<typeof StashedRequest>) {\n\t\tif (typeof window === 'undefined' || !window.opener) {\n\t\t\tthrow new Error(\n\t\t\t\t'StashedHost can only be used in a window opened through `window.open`. `window.opener` is not available.',\n\t\t\t);\n\t\t}\n\n\t\tthis.#request = request;\n\t}\n\n\tstatic fromUrl(url: string = window.location.href) {\n\t\tconst parsed = new URL(url);\n\n\t\tconst urlHashData = parsed.hash\n\t\t\t? Object.fromEntries([...new URLSearchParams(parsed.hash.slice(1))])\n\t\t\t: {};\n\n\t\tconst request = parse(StashedRequest, {\n\t\t\tid: parsed.searchParams.get('id'),\n\t\t\torigin: parsed.searchParams.get('origin'),\n\t\t\tname: parsed.searchParams.get('name'),\n\t\t\tpayload: {\n\t\t\t\ttype: parsed.pathname.split('/').pop(),\n\t\t\t\t...urlHashData,\n\t\t\t},\n\t\t});\n\n\t\treturn new StashedHost(request);\n\t}\n\n\tgetRequestData() {\n\t\treturn this.#request;\n\t}\n\n\tsendMessage(payload: StashedResponsePayload) {\n\t\twindow.opener.postMessage(\n\t\t\t{\n\t\t\t\tid: this.#request.id,\n\t\t\t\tsource: '
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { InferOutput } from 'valibot';\nimport { parse, safeParse } from 'valibot';\n\nimport { withResolvers } from '../../utils/withResolvers.js';\nimport type { StashedSupportedNetwork } from '../types.js';\nimport type { StashedRequestData, StashedResponsePayload, StashedResponseTypes } from './events.js';\nimport { StashedRequest, StashedResponse } from './events.js';\n\nexport const DEFAULT_STASHED_ORIGIN = 'https://getstashed.com';\n\nexport { StashedRequest, StashedResponse };\n\nexport class StashedPopup {\n\t#popup: Window;\n\n\t#id: string;\n\t#origin: string;\n\t#name: string;\n\t#network: StashedSupportedNetwork;\n\n\t#promise: Promise<unknown>;\n\t#resolve: (data: unknown) => void;\n\t#reject: (error: Error) => void;\n\n\t#interval: ReturnType<typeof setInterval> | null = null;\n\n\tconstructor({\n\t\tname,\n\t\tnetwork,\n\t\torigin = DEFAULT_STASHED_ORIGIN,\n\t}: {\n\t\tname: string;\n\t\tnetwork: StashedSupportedNetwork;\n\t\torigin?: string;\n\t}) {\n\t\tconst popup = window.open('about:blank', '_blank');\n\n\t\tif (!popup) {\n\t\t\tthrow new Error('Failed to open new window');\n\t\t}\n\t\tthis.#popup = popup;\n\n\t\tthis.#id = crypto.randomUUID();\n\t\tthis.#origin = origin;\n\t\tthis.#name = name;\n\t\tthis.#network = network;\n\n\t\tconst { promise, resolve, reject } = withResolvers();\n\t\tthis.#promise = promise;\n\t\tthis.#resolve = resolve;\n\t\tthis.#reject = reject;\n\n\t\tthis.#interval = setInterval(() => {\n\t\t\ttry {\n\t\t\t\tif (this.#popup.closed) {\n\t\t\t\t\tthis.#cleanup();\n\t\t\t\t\treject(new Error('User closed the Stashed window'));\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// This can error during the login flow, but that's fine.\n\t\t\t}\n\t\t}, 1000);\n\t}\n\n\tsend<T extends StashedRequestData['type']>({\n\t\ttype,\n\t\t...data\n\t}: {\n\t\ttype: T;\n\t} & Extract<StashedRequestData, { type: T }>): Promise<StashedResponseTypes[T]> {\n\t\twindow.addEventListener('message', this.#listener);\n\t\tthis.#popup.location.assign(\n\t\t\t`${this.#origin}/dapp/${type}?${new URLSearchParams({\n\t\t\t\tid: this.#id,\n\t\t\t\torigin: window.origin,\n\t\t\t\tnetwork: this.#network,\n\t\t\t\tname: this.#name,\n\t\t\t})}${data ? `#${new URLSearchParams(data as never)}` : ''}`,\n\t\t);\n\n\t\treturn this.#promise as Promise<StashedResponseTypes[T]>;\n\t}\n\n\tclose() {\n\t\tthis.#cleanup();\n\t\tthis.#popup.close();\n\t}\n\n\t#listener = (event: MessageEvent) => {\n\t\tif (event.origin !== this.#origin) {\n\t\t\treturn;\n\t\t}\n\t\tconst { success, output } = safeParse(StashedResponse, event.data);\n\t\tif (!success || output.id !== this.#id) return;\n\n\t\tthis.#cleanup();\n\n\t\tif (output.payload.type === 'reject') {\n\t\t\tthis.#reject(new Error('User rejected the request'));\n\t\t} else if (output.payload.type === 'resolve') {\n\t\t\tthis.#resolve(output.payload.data);\n\t\t}\n\t};\n\n\t#cleanup() {\n\t\tif (this.#interval) {\n\t\t\tclearInterval(this.#interval);\n\t\t\tthis.#interval = null;\n\t\t}\n\t\twindow.removeEventListener('message', this.#listener);\n\t}\n}\n\nexport class StashedHost {\n\t#request: InferOutput<typeof StashedRequest>;\n\n\tconstructor(request: InferOutput<typeof StashedRequest>) {\n\t\tif (typeof window === 'undefined' || !window.opener) {\n\t\t\tthrow new Error(\n\t\t\t\t'StashedHost can only be used in a window opened through `window.open`. `window.opener` is not available.',\n\t\t\t);\n\t\t}\n\n\t\tthis.#request = request;\n\t}\n\n\tstatic fromUrl(url: string = window.location.href) {\n\t\tconst parsed = new URL(url);\n\n\t\tconst urlHashData = parsed.hash\n\t\t\t? Object.fromEntries([...new URLSearchParams(parsed.hash.slice(1))])\n\t\t\t: {};\n\n\t\tconst request = parse(StashedRequest, {\n\t\t\tid: parsed.searchParams.get('id'),\n\t\t\torigin: parsed.searchParams.get('origin'),\n\t\t\tname: parsed.searchParams.get('name'),\n\t\t\tpayload: {\n\t\t\t\ttype: parsed.pathname.split('/').pop(),\n\t\t\t\t...urlHashData,\n\t\t\t},\n\t\t});\n\n\t\treturn new StashedHost(request);\n\t}\n\n\tgetRequestData() {\n\t\treturn this.#request;\n\t}\n\n\tsendMessage(payload: StashedResponsePayload) {\n\t\twindow.opener.postMessage(\n\t\t\t{\n\t\t\t\tid: this.#request.id,\n\t\t\t\tsource: 'zksend-channel',\n\t\t\t\tpayload,\n\t\t\t} satisfies StashedResponse,\n\t\t\tthis.#request.origin,\n\t\t);\n\t}\n\n\tclose(payload?: StashedResponsePayload) {\n\t\tif (payload) {\n\t\t\tthis.sendMessage(payload);\n\t\t}\n\t\twindow.close();\n\t}\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,qBAAiC;AAEjC,2BAA8B;AAG9B,oBAAgD;AAThD;AAWO,MAAM,yBAAyB;AAI/B,MAAM,aAAa;AAAA,EAczB,YAAY;AAAA,IACX;AAAA,IACA;AAAA,IACA,SAAS;AAAA,EACV,GAIG;AAtBG;AACN;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AAEA,kCAAmD;AAgEnD,kCAAY,CAAC,UAAwB;AACpC,UAAI,MAAM,WAAW,mBAAK,UAAS;AAClC;AAAA,MACD;AACA,YAAM,EAAE,SAAS,OAAO,QAAI,0BAAU,+BAAiB,MAAM,IAAI;AACjE,UAAI,CAAC,WAAW,OAAO,OAAO,mBAAK,KAAK;AAExC,4BAAK,qCAAL;AAEA,UAAI,OAAO,QAAQ,SAAS,UAAU;AACrC,2BAAK,SAAL,WAAa,IAAI,MAAM,2BAA2B;AAAA,MACnD,WAAW,OAAO,QAAQ,SAAS,WAAW;AAC7C,2BAAK,UAAL,WAAc,OAAO,QAAQ;AAAA,MAC9B;AAAA,IACD;AAnEC,UAAM,QAAQ,OAAO,KAAK,eAAe,QAAQ;AAEjD,QAAI,CAAC,OAAO;AACX,YAAM,IAAI,MAAM,2BAA2B;AAAA,IAC5C;AACA,uBAAK,QAAS;AAEd,uBAAK,KAAM,OAAO,WAAW;AAC7B,uBAAK,SAAU;AACf,uBAAK,OAAQ;AACb,uBAAK,UAAW;AAEhB,UAAM,EAAE,SAAS,SAAS,OAAO,QAAI,oCAAc;AACnD,uBAAK,UAAW;AAChB,uBAA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E1B,UAAM,cAAc,OAAO,OACxB,OAAO,YAAY,CAAC,GAAG,IAAI,gBAAgB,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,IACjE,CAAC;AAEJ,UAAM,cAAU,sBAAM,8BAAgB;AAAA,MACrC,IAAI,OAAO,aAAa,IAAI,IAAI;AAAA,MAChC,QAAQ,OAAO,aAAa,IAAI,QAAQ;AAAA,MACxC,MAAM,OAAO,aAAa,IAAI,MAAM;AAAA,MACpC,SAAS;AAAA,QACR,MAAM,OAAO,SAAS,MAAM,GAAG,EAAE,IAAI;AAAA,QACrC,GAAG;AAAA,MACJ;AAAA,IACD,CAAC;AAED,WAAO,IAAI,aAAY,OAAO;AAAA,EAC/B;AAAA,EAEA,iBAAiB;AAChB,WAAO,mBAAK;AAAA,EACb;AAAA,EAEA,YAAY,SAAiC;AAC5C,WAAO,OAAO;AAAA,MACb;AAAA,QACC,IAAI,mBAAK,UAAS;AAAA,QAClB,QAAQ;AAAA,QACR;AAAA,MACD;AAAA,MACA,mBAAK,UAAS;AAAA,IACf;AAAA,EACD;AAAA,EAEA,MAAM,SAAkC;AACvC,QAAI,SAAS;AACZ,WAAK,YAAY,OAAO;AAAA,IACzB;AACA,WAAO,MAAM;AAAA,EACd;AACD;AArDC;AADM,IAAM,cAAN;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -61,7 +61,7 @@ export declare const StashedResponsePayload: import("valibot").VariantSchema<"ty
|
|
|
61
61
|
export type StashedResponsePayload = InferOutput<typeof StashedResponsePayload>;
|
|
62
62
|
export declare const StashedResponse: import("valibot").ObjectSchema<{
|
|
63
63
|
readonly id: import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").UuidAction<string, undefined>]>;
|
|
64
|
-
readonly source: import("valibot").LiteralSchema<"
|
|
64
|
+
readonly source: import("valibot").LiteralSchema<"zksend-channel", undefined>;
|
|
65
65
|
readonly payload: import("valibot").VariantSchema<"type", [import("valibot").ObjectSchema<{
|
|
66
66
|
readonly type: import("valibot").LiteralSchema<"reject", undefined>;
|
|
67
67
|
}, undefined>, import("valibot").ObjectSchema<{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/wallet/channel/events.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { InferOutput } from 'valibot';\nimport { literal, object, optional, pipe, string, url, uuid, variant } from 'valibot';\n\nexport const StashedRequestData = variant('type', [\n\tobject({\n\t\ttype: literal('connect'),\n\t}),\n\tobject({\n\t\ttype: literal('sign-transaction-block'),\n\t\tdata: string('`data` is required'),\n\t\taddress: string('`address` is required'),\n\t}),\n\tobject({\n\t\ttype: literal('sign-personal-message'),\n\t\tbytes: string('`bytes` is required'),\n\t\taddress: string('`address` is required'),\n\t}),\n]);\nexport type StashedRequestData = InferOutput<typeof StashedRequestData>;\n\nexport const StashedRequest = object({\n\tid: pipe(string('`id` is required'), uuid()),\n\torigin: pipe(string(), url('`origin` must be a valid URL')),\n\tname: optional(string()),\n\tpayload: StashedRequestData,\n});\n\nexport type StashedRequest = InferOutput<typeof StashedRequest>;\n\nexport const StashedResponseData = variant('type', [\n\tobject({\n\t\ttype: literal('connect'),\n\t\taddress: string(),\n\t}),\n\tobject({\n\t\ttype: literal('sign-transaction-block'),\n\t\tbytes: string(),\n\t\tsignature: string(),\n\t}),\n\tobject({\n\t\ttype: literal('sign-personal-message'),\n\t\tbytes: string(),\n\t\tsignature: string(),\n\t}),\n]);\nexport type StashedResponseData = InferOutput<typeof StashedResponseData>;\n\nexport const StashedResponsePayload = variant('type', [\n\tobject({\n\t\ttype: literal('reject'),\n\t}),\n\tobject({\n\t\ttype: literal('resolve'),\n\t\tdata: StashedResponseData,\n\t}),\n]);\nexport type StashedResponsePayload = InferOutput<typeof StashedResponsePayload>;\n\nexport const StashedResponse = object({\n\tid: pipe(string(), uuid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ACF,CAAC;AAGM,MAAM,kBAAkB,OAAO;AAAA,EACrC,IAAI,KAAK,OAAO,GAAG,KAAK,CAAC;AAAA,EACzB,QAAQ,QAAQ,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { InferOutput } from 'valibot';\nimport { literal, object, optional, pipe, string, url, uuid, variant } from 'valibot';\n\nexport const StashedRequestData = variant('type', [\n\tobject({\n\t\ttype: literal('connect'),\n\t}),\n\tobject({\n\t\ttype: literal('sign-transaction-block'),\n\t\tdata: string('`data` is required'),\n\t\taddress: string('`address` is required'),\n\t}),\n\tobject({\n\t\ttype: literal('sign-personal-message'),\n\t\tbytes: string('`bytes` is required'),\n\t\taddress: string('`address` is required'),\n\t}),\n]);\nexport type StashedRequestData = InferOutput<typeof StashedRequestData>;\n\nexport const StashedRequest = object({\n\tid: pipe(string('`id` is required'), uuid()),\n\torigin: pipe(string(), url('`origin` must be a valid URL')),\n\tname: optional(string()),\n\tpayload: StashedRequestData,\n});\n\nexport type StashedRequest = InferOutput<typeof StashedRequest>;\n\nexport const StashedResponseData = variant('type', [\n\tobject({\n\t\ttype: literal('connect'),\n\t\taddress: string(),\n\t}),\n\tobject({\n\t\ttype: literal('sign-transaction-block'),\n\t\tbytes: string(),\n\t\tsignature: string(),\n\t}),\n\tobject({\n\t\ttype: literal('sign-personal-message'),\n\t\tbytes: string(),\n\t\tsignature: string(),\n\t}),\n]);\nexport type StashedResponseData = InferOutput<typeof StashedResponseData>;\n\nexport const StashedResponsePayload = variant('type', [\n\tobject({\n\t\ttype: literal('reject'),\n\t}),\n\tobject({\n\t\ttype: literal('resolve'),\n\t\tdata: StashedResponseData,\n\t}),\n]);\nexport type StashedResponsePayload = InferOutput<typeof StashedResponsePayload>;\n\nexport const StashedResponse = object({\n\tid: pipe(string(), uuid()),\n\tsource: literal('zksend-channel'),\n\tpayload: StashedResponsePayload,\n});\nexport type StashedResponse = InferOutput<typeof StashedResponse>;\n\nexport type StashedRequestTypes = Record<string, any> & {\n\t[P in StashedRequestData as P['type']]: P;\n};\n\nexport type StashedResponseTypes = {\n\t[P in StashedResponseData as P['type']]: P;\n};\n"],
|
|
5
|
+
"mappings": "AAIA,SAAS,SAAS,QAAQ,UAAU,MAAM,QAAQ,KAAK,MAAM,eAAe;AAErE,MAAM,qBAAqB,QAAQ,QAAQ;AAAA,EACjD,OAAO;AAAA,IACN,MAAM,QAAQ,SAAS;AAAA,EACxB,CAAC;AAAA,EACD,OAAO;AAAA,IACN,MAAM,QAAQ,wBAAwB;AAAA,IACtC,MAAM,OAAO,oBAAoB;AAAA,IACjC,SAAS,OAAO,uBAAuB;AAAA,EACxC,CAAC;AAAA,EACD,OAAO;AAAA,IACN,MAAM,QAAQ,uBAAuB;AAAA,IACrC,OAAO,OAAO,qBAAqB;AAAA,IACnC,SAAS,OAAO,uBAAuB;AAAA,EACxC,CAAC;AACF,CAAC;AAGM,MAAM,iBAAiB,OAAO;AAAA,EACpC,IAAI,KAAK,OAAO,kBAAkB,GAAG,KAAK,CAAC;AAAA,EAC3C,QAAQ,KAAK,OAAO,GAAG,IAAI,8BAA8B,CAAC;AAAA,EAC1D,MAAM,SAAS,OAAO,CAAC;AAAA,EACvB,SAAS;AACV,CAAC;AAIM,MAAM,sBAAsB,QAAQ,QAAQ;AAAA,EAClD,OAAO;AAAA,IACN,MAAM,QAAQ,SAAS;AAAA,IACvB,SAAS,OAAO;AAAA,EACjB,CAAC;AAAA,EACD,OAAO;AAAA,IACN,MAAM,QAAQ,wBAAwB;AAAA,IACtC,OAAO,OAAO;AAAA,IACd,WAAW,OAAO;AAAA,EACnB,CAAC;AAAA,EACD,OAAO;AAAA,IACN,MAAM,QAAQ,uBAAuB;AAAA,IACrC,OAAO,OAAO;AAAA,IACd,WAAW,OAAO;AAAA,EACnB,CAAC;AACF,CAAC;AAGM,MAAM,yBAAyB,QAAQ,QAAQ;AAAA,EACrD,OAAO;AAAA,IACN,MAAM,QAAQ,QAAQ;AAAA,EACvB,CAAC;AAAA,EACD,OAAO;AAAA,IACN,MAAM,QAAQ,SAAS;AAAA,IACvB,MAAM;AAAA,EACP,CAAC;AACF,CAAC;AAGM,MAAM,kBAAkB,OAAO;AAAA,EACrC,IAAI,KAAK,OAAO,GAAG,KAAK,CAAC;AAAA,EACzB,QAAQ,QAAQ,gBAAgB;AAAA,EAChC,SAAS;AACV,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/wallet/channel/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { InferOutput } from 'valibot';\nimport { parse, safeParse } from 'valibot';\n\nimport { withResolvers } from '../../utils/withResolvers.js';\nimport type { StashedSupportedNetwork } from '../types.js';\nimport type { StashedRequestData, StashedResponsePayload, StashedResponseTypes } from './events.js';\nimport { StashedRequest, StashedResponse } from './events.js';\n\nexport const DEFAULT_STASHED_ORIGIN = 'https://getstashed.com';\n\nexport { StashedRequest, StashedResponse };\n\nexport class StashedPopup {\n\t#popup: Window;\n\n\t#id: string;\n\t#origin: string;\n\t#name: string;\n\t#network: StashedSupportedNetwork;\n\n\t#promise: Promise<unknown>;\n\t#resolve: (data: unknown) => void;\n\t#reject: (error: Error) => void;\n\n\t#interval: ReturnType<typeof setInterval> | null = null;\n\n\tconstructor({\n\t\tname,\n\t\tnetwork,\n\t\torigin = DEFAULT_STASHED_ORIGIN,\n\t}: {\n\t\tname: string;\n\t\tnetwork: StashedSupportedNetwork;\n\t\torigin?: string;\n\t}) {\n\t\tconst popup = window.open('about:blank', '_blank');\n\n\t\tif (!popup) {\n\t\t\tthrow new Error('Failed to open new window');\n\t\t}\n\t\tthis.#popup = popup;\n\n\t\tthis.#id = crypto.randomUUID();\n\t\tthis.#origin = origin;\n\t\tthis.#name = name;\n\t\tthis.#network = network;\n\n\t\tconst { promise, resolve, reject } = withResolvers();\n\t\tthis.#promise = promise;\n\t\tthis.#resolve = resolve;\n\t\tthis.#reject = reject;\n\n\t\tthis.#interval = setInterval(() => {\n\t\t\ttry {\n\t\t\t\tif (this.#popup.closed) {\n\t\t\t\t\tthis.#cleanup();\n\t\t\t\t\treject(new Error('User closed the Stashed window'));\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// This can error during the login flow, but that's fine.\n\t\t\t}\n\t\t}, 1000);\n\t}\n\n\tsend<T extends StashedRequestData['type']>({\n\t\ttype,\n\t\t...data\n\t}: {\n\t\ttype: T;\n\t} & Extract<StashedRequestData, { type: T }>): Promise<StashedResponseTypes[T]> {\n\t\twindow.addEventListener('message', this.#listener);\n\t\tthis.#popup.location.assign(\n\t\t\t`${this.#origin}/dapp/${type}?${new URLSearchParams({\n\t\t\t\tid: this.#id,\n\t\t\t\torigin: window.origin,\n\t\t\t\tnetwork: this.#network,\n\t\t\t\tname: this.#name,\n\t\t\t})}${data ? `#${new URLSearchParams(data as never)}` : ''}`,\n\t\t);\n\n\t\treturn this.#promise as Promise<StashedResponseTypes[T]>;\n\t}\n\n\tclose() {\n\t\tthis.#cleanup();\n\t\tthis.#popup.close();\n\t}\n\n\t#listener = (event: MessageEvent) => {\n\t\tif (event.origin !== this.#origin) {\n\t\t\treturn;\n\t\t}\n\t\tconst { success, output } = safeParse(StashedResponse, event.data);\n\t\tif (!success || output.id !== this.#id) return;\n\n\t\tthis.#cleanup();\n\n\t\tif (output.payload.type === 'reject') {\n\t\t\tthis.#reject(new Error('User rejected the request'));\n\t\t} else if (output.payload.type === 'resolve') {\n\t\t\tthis.#resolve(output.payload.data);\n\t\t}\n\t};\n\n\t#cleanup() {\n\t\tif (this.#interval) {\n\t\t\tclearInterval(this.#interval);\n\t\t\tthis.#interval = null;\n\t\t}\n\t\twindow.removeEventListener('message', this.#listener);\n\t}\n}\n\nexport class StashedHost {\n\t#request: InferOutput<typeof StashedRequest>;\n\n\tconstructor(request: InferOutput<typeof StashedRequest>) {\n\t\tif (typeof window === 'undefined' || !window.opener) {\n\t\t\tthrow new Error(\n\t\t\t\t'StashedHost can only be used in a window opened through `window.open`. `window.opener` is not available.',\n\t\t\t);\n\t\t}\n\n\t\tthis.#request = request;\n\t}\n\n\tstatic fromUrl(url: string = window.location.href) {\n\t\tconst parsed = new URL(url);\n\n\t\tconst urlHashData = parsed.hash\n\t\t\t? Object.fromEntries([...new URLSearchParams(parsed.hash.slice(1))])\n\t\t\t: {};\n\n\t\tconst request = parse(StashedRequest, {\n\t\t\tid: parsed.searchParams.get('id'),\n\t\t\torigin: parsed.searchParams.get('origin'),\n\t\t\tname: parsed.searchParams.get('name'),\n\t\t\tpayload: {\n\t\t\t\ttype: parsed.pathname.split('/').pop(),\n\t\t\t\t...urlHashData,\n\t\t\t},\n\t\t});\n\n\t\treturn new StashedHost(request);\n\t}\n\n\tgetRequestData() {\n\t\treturn this.#request;\n\t}\n\n\tsendMessage(payload: StashedResponsePayload) {\n\t\twindow.opener.postMessage(\n\t\t\t{\n\t\t\t\tid: this.#request.id,\n\t\t\t\tsource: '
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { InferOutput } from 'valibot';\nimport { parse, safeParse } from 'valibot';\n\nimport { withResolvers } from '../../utils/withResolvers.js';\nimport type { StashedSupportedNetwork } from '../types.js';\nimport type { StashedRequestData, StashedResponsePayload, StashedResponseTypes } from './events.js';\nimport { StashedRequest, StashedResponse } from './events.js';\n\nexport const DEFAULT_STASHED_ORIGIN = 'https://getstashed.com';\n\nexport { StashedRequest, StashedResponse };\n\nexport class StashedPopup {\n\t#popup: Window;\n\n\t#id: string;\n\t#origin: string;\n\t#name: string;\n\t#network: StashedSupportedNetwork;\n\n\t#promise: Promise<unknown>;\n\t#resolve: (data: unknown) => void;\n\t#reject: (error: Error) => void;\n\n\t#interval: ReturnType<typeof setInterval> | null = null;\n\n\tconstructor({\n\t\tname,\n\t\tnetwork,\n\t\torigin = DEFAULT_STASHED_ORIGIN,\n\t}: {\n\t\tname: string;\n\t\tnetwork: StashedSupportedNetwork;\n\t\torigin?: string;\n\t}) {\n\t\tconst popup = window.open('about:blank', '_blank');\n\n\t\tif (!popup) {\n\t\t\tthrow new Error('Failed to open new window');\n\t\t}\n\t\tthis.#popup = popup;\n\n\t\tthis.#id = crypto.randomUUID();\n\t\tthis.#origin = origin;\n\t\tthis.#name = name;\n\t\tthis.#network = network;\n\n\t\tconst { promise, resolve, reject } = withResolvers();\n\t\tthis.#promise = promise;\n\t\tthis.#resolve = resolve;\n\t\tthis.#reject = reject;\n\n\t\tthis.#interval = setInterval(() => {\n\t\t\ttry {\n\t\t\t\tif (this.#popup.closed) {\n\t\t\t\t\tthis.#cleanup();\n\t\t\t\t\treject(new Error('User closed the Stashed window'));\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// This can error during the login flow, but that's fine.\n\t\t\t}\n\t\t}, 1000);\n\t}\n\n\tsend<T extends StashedRequestData['type']>({\n\t\ttype,\n\t\t...data\n\t}: {\n\t\ttype: T;\n\t} & Extract<StashedRequestData, { type: T }>): Promise<StashedResponseTypes[T]> {\n\t\twindow.addEventListener('message', this.#listener);\n\t\tthis.#popup.location.assign(\n\t\t\t`${this.#origin}/dapp/${type}?${new URLSearchParams({\n\t\t\t\tid: this.#id,\n\t\t\t\torigin: window.origin,\n\t\t\t\tnetwork: this.#network,\n\t\t\t\tname: this.#name,\n\t\t\t})}${data ? `#${new URLSearchParams(data as never)}` : ''}`,\n\t\t);\n\n\t\treturn this.#promise as Promise<StashedResponseTypes[T]>;\n\t}\n\n\tclose() {\n\t\tthis.#cleanup();\n\t\tthis.#popup.close();\n\t}\n\n\t#listener = (event: MessageEvent) => {\n\t\tif (event.origin !== this.#origin) {\n\t\t\treturn;\n\t\t}\n\t\tconst { success, output } = safeParse(StashedResponse, event.data);\n\t\tif (!success || output.id !== this.#id) return;\n\n\t\tthis.#cleanup();\n\n\t\tif (output.payload.type === 'reject') {\n\t\t\tthis.#reject(new Error('User rejected the request'));\n\t\t} else if (output.payload.type === 'resolve') {\n\t\t\tthis.#resolve(output.payload.data);\n\t\t}\n\t};\n\n\t#cleanup() {\n\t\tif (this.#interval) {\n\t\t\tclearInterval(this.#interval);\n\t\t\tthis.#interval = null;\n\t\t}\n\t\twindow.removeEventListener('message', this.#listener);\n\t}\n}\n\nexport class StashedHost {\n\t#request: InferOutput<typeof StashedRequest>;\n\n\tconstructor(request: InferOutput<typeof StashedRequest>) {\n\t\tif (typeof window === 'undefined' || !window.opener) {\n\t\t\tthrow new Error(\n\t\t\t\t'StashedHost can only be used in a window opened through `window.open`. `window.opener` is not available.',\n\t\t\t);\n\t\t}\n\n\t\tthis.#request = request;\n\t}\n\n\tstatic fromUrl(url: string = window.location.href) {\n\t\tconst parsed = new URL(url);\n\n\t\tconst urlHashData = parsed.hash\n\t\t\t? Object.fromEntries([...new URLSearchParams(parsed.hash.slice(1))])\n\t\t\t: {};\n\n\t\tconst request = parse(StashedRequest, {\n\t\t\tid: parsed.searchParams.get('id'),\n\t\t\torigin: parsed.searchParams.get('origin'),\n\t\t\tname: parsed.searchParams.get('name'),\n\t\t\tpayload: {\n\t\t\t\ttype: parsed.pathname.split('/').pop(),\n\t\t\t\t...urlHashData,\n\t\t\t},\n\t\t});\n\n\t\treturn new StashedHost(request);\n\t}\n\n\tgetRequestData() {\n\t\treturn this.#request;\n\t}\n\n\tsendMessage(payload: StashedResponsePayload) {\n\t\twindow.opener.postMessage(\n\t\t\t{\n\t\t\t\tid: this.#request.id,\n\t\t\t\tsource: 'zksend-channel',\n\t\t\t\tpayload,\n\t\t\t} satisfies StashedResponse,\n\t\t\tthis.#request.origin,\n\t\t);\n\t}\n\n\tclose(payload?: StashedResponsePayload) {\n\t\tif (payload) {\n\t\t\tthis.sendMessage(payload);\n\t\t}\n\t\twindow.close();\n\t}\n}\n"],
|
|
5
5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