@worldcoin/minikit-js 0.0.1

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.
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ Command: () => Command,
24
+ Currency: () => Currency,
25
+ MiniKit: () => MiniKit,
26
+ Network: () => Network,
27
+ ResponseEvent: () => ResponseEvent,
28
+ VerificationLevel: () => import_idkit_core.VerificationLevel
29
+ });
30
+ module.exports = __toCommonJS(src_exports);
31
+
32
+ // helpers/send-webview-event.ts
33
+ var sendWebviewEvent = (payload) => {
34
+ if (window.webkit) {
35
+ window.webkit?.messageHandlers?.minikit?.postMessage?.(payload);
36
+ } else if (window.Android) {
37
+ window.Android.minikit?.()?.sendEvent?.(JSON.stringify(payload));
38
+ }
39
+ };
40
+
41
+ // types/commands.ts
42
+ var Command = /* @__PURE__ */ ((Command2) => {
43
+ Command2["Verify"] = "verify";
44
+ Command2["Pay"] = "pay";
45
+ return Command2;
46
+ })(Command || {});
47
+
48
+ // types/responses.ts
49
+ var ResponseEvent = /* @__PURE__ */ ((ResponseEvent2) => {
50
+ ResponseEvent2["MiniAppVerifyAction"] = "miniapp-verify-action";
51
+ ResponseEvent2["MiniAppPaymentInitiated"] = "miniapp-payment-initiated";
52
+ ResponseEvent2["MiniAppPaymentCompleted"] = "miniapp-payment-completed";
53
+ return ResponseEvent2;
54
+ })(ResponseEvent || {});
55
+
56
+ // types/payment.ts
57
+ var Currency = /* @__PURE__ */ ((Currency2) => {
58
+ Currency2["WLD"] = "wld";
59
+ Currency2["ETH"] = "eth";
60
+ Currency2["USDC"] = "usdc";
61
+ return Currency2;
62
+ })(Currency || {});
63
+ var Network = /* @__PURE__ */ ((Network2) => {
64
+ Network2["Optimism"] = "optimism";
65
+ return Network2;
66
+ })(Network || {});
67
+
68
+ // minikit.ts
69
+ var sendMiniKitEvent = (payload) => {
70
+ sendWebviewEvent(payload);
71
+ };
72
+ var _MiniKit = class _MiniKit {
73
+ static subscribe(event, handler) {
74
+ this.listeners[event] = handler;
75
+ }
76
+ static unsubscribe(event) {
77
+ delete this.listeners[event];
78
+ }
79
+ static trigger(event, payload) {
80
+ if (!this.listeners[event]) {
81
+ return;
82
+ }
83
+ this.listeners[event](payload);
84
+ }
85
+ static install({ app_id }) {
86
+ this.appId = app_id;
87
+ if (typeof window !== "undefined" && !Boolean(window.MiniKit)) {
88
+ try {
89
+ window.MiniKit = _MiniKit;
90
+ } catch (error) {
91
+ console.error("Failed to install MiniKit", error);
92
+ return { success: false, error };
93
+ }
94
+ }
95
+ return { success: true };
96
+ }
97
+ static isInstalled() {
98
+ console.log("MiniKit is alive!");
99
+ return true;
100
+ }
101
+ };
102
+ _MiniKit.listeners = {
103
+ ["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
104
+ },
105
+ ["miniapp-payment-initiated" /* MiniAppPaymentInitiated */]: () => {
106
+ },
107
+ ["miniapp-payment-completed" /* MiniAppPaymentCompleted */]: () => {
108
+ }
109
+ };
110
+ _MiniKit.commands = {
111
+ verify: (payload) => {
112
+ sendMiniKitEvent({ command: "verify" /* Verify */, payload });
113
+ },
114
+ pay: (payload) => {
115
+ sendMiniKitEvent({
116
+ command: "pay" /* Pay */,
117
+ app_id: _MiniKit.appId,
118
+ payload
119
+ });
120
+ },
121
+ closeWebview: () => {
122
+ sendWebviewEvent({ command: "close" });
123
+ }
124
+ };
125
+ var MiniKit = _MiniKit;
126
+
127
+ // index.ts
128
+ var import_idkit_core = require("@worldcoin/idkit-core");
129
+ // Annotate the CommonJS export names for ESM import in node:
130
+ 0 && (module.exports = {
131
+ Command,
132
+ Currency,
133
+ MiniKit,
134
+ Network,
135
+ ResponseEvent,
136
+ VerificationLevel
137
+ });
@@ -0,0 +1,105 @@
1
+ import { VerificationLevel } from '@worldcoin/idkit-core';
2
+ export { VerificationLevel } from '@worldcoin/idkit-core';
3
+
4
+ declare enum Command {
5
+ Verify = "verify",
6
+ Pay = "pay"
7
+ }
8
+ type WebViewBasePayload = {
9
+ command: Command;
10
+ payload: Record<string, any>;
11
+ };
12
+ type VerifyCommandInput = {
13
+ app_id: `app_${string}`;
14
+ action: string;
15
+ signal: string;
16
+ verification_level: string;
17
+ timestamp: string;
18
+ };
19
+ type PayCommandInput = {
20
+ to: string;
21
+ from: string;
22
+ value: number;
23
+ network: string;
24
+ token_address: string;
25
+ token: string;
26
+ timestamp: string;
27
+ };
28
+
29
+ declare enum ResponseEvent {
30
+ MiniAppVerifyAction = "miniapp-verify-action",
31
+ MiniAppPaymentInitiated = "miniapp-payment-initiated",
32
+ MiniAppPaymentCompleted = "miniapp-payment-completed"
33
+ }
34
+ type MiniAppVerifyActionPayload = {
35
+ command: ResponseEvent.MiniAppVerifyAction;
36
+ payload: {
37
+ status: "success" | "error";
38
+ error_code: string;
39
+ error_message: string;
40
+ proof: string;
41
+ merkle_root: string;
42
+ nullifier_hash: string;
43
+ verification_level: VerificationLevel;
44
+ };
45
+ };
46
+ type MiniAppPaymentInitiatedPayload = {
47
+ event: ResponseEvent.MiniAppPaymentInitiated;
48
+ payload: {
49
+ transaction_hash: string;
50
+ status: "completed" | "error";
51
+ chain: string;
52
+ nonce?: string;
53
+ timestamp: string;
54
+ error_code?: string;
55
+ error_message?: string;
56
+ };
57
+ };
58
+ type MiniAppPaymentCompletedPayload = {
59
+ event: ResponseEvent.MiniAppPaymentCompleted;
60
+ payload: {
61
+ transaction_hash: string;
62
+ "status:": "completed" | "error";
63
+ chain: string;
64
+ nonce?: string;
65
+ timestamp: string;
66
+ error_code?: string;
67
+ error_message?: string;
68
+ };
69
+ };
70
+ type EventPayload<T extends ResponseEvent = ResponseEvent> = T extends ResponseEvent.MiniAppVerifyAction ? MiniAppVerifyActionPayload : T extends ResponseEvent.MiniAppPaymentInitiated ? MiniAppPaymentInitiatedPayload : T extends ResponseEvent.MiniAppPaymentCompleted ? MiniAppPaymentCompletedPayload : unknown;
71
+ type EventHandler<E extends ResponseEvent = ResponseEvent> = <T extends EventPayload<E>>(data: T) => void;
72
+
73
+ declare enum Currency {
74
+ WLD = "wld",
75
+ ETH = "eth",
76
+ USDC = "usdc"
77
+ }
78
+ declare enum Network {
79
+ Optimism = "optimism"
80
+ }
81
+
82
+ declare class MiniKit {
83
+ private static appId;
84
+ private static listeners;
85
+ static subscribe<E extends ResponseEvent>(event: E, handler: EventHandler<E>): void;
86
+ static unsubscribe(event: ResponseEvent): void;
87
+ static trigger(event: ResponseEvent, payload: EventPayload): void;
88
+ static install({ app_id }: {
89
+ app_id: `app_${string}`;
90
+ }): {
91
+ success: boolean;
92
+ error: unknown;
93
+ } | {
94
+ success: boolean;
95
+ error?: undefined;
96
+ };
97
+ static isInstalled(): boolean;
98
+ static commands: {
99
+ verify: (payload: VerifyCommandInput) => void;
100
+ pay: (payload: PayCommandInput) => void;
101
+ closeWebview: () => void;
102
+ };
103
+ }
104
+
105
+ export { Command, Currency, type MiniAppPaymentCompletedPayload, type MiniAppPaymentInitiatedPayload, type MiniAppVerifyActionPayload, MiniKit, Network, type PayCommandInput, ResponseEvent, type VerifyCommandInput, type WebViewBasePayload };
@@ -0,0 +1,105 @@
1
+ import { VerificationLevel } from '@worldcoin/idkit-core';
2
+ export { VerificationLevel } from '@worldcoin/idkit-core';
3
+
4
+ declare enum Command {
5
+ Verify = "verify",
6
+ Pay = "pay"
7
+ }
8
+ type WebViewBasePayload = {
9
+ command: Command;
10
+ payload: Record<string, any>;
11
+ };
12
+ type VerifyCommandInput = {
13
+ app_id: `app_${string}`;
14
+ action: string;
15
+ signal: string;
16
+ verification_level: string;
17
+ timestamp: string;
18
+ };
19
+ type PayCommandInput = {
20
+ to: string;
21
+ from: string;
22
+ value: number;
23
+ network: string;
24
+ token_address: string;
25
+ token: string;
26
+ timestamp: string;
27
+ };
28
+
29
+ declare enum ResponseEvent {
30
+ MiniAppVerifyAction = "miniapp-verify-action",
31
+ MiniAppPaymentInitiated = "miniapp-payment-initiated",
32
+ MiniAppPaymentCompleted = "miniapp-payment-completed"
33
+ }
34
+ type MiniAppVerifyActionPayload = {
35
+ command: ResponseEvent.MiniAppVerifyAction;
36
+ payload: {
37
+ status: "success" | "error";
38
+ error_code: string;
39
+ error_message: string;
40
+ proof: string;
41
+ merkle_root: string;
42
+ nullifier_hash: string;
43
+ verification_level: VerificationLevel;
44
+ };
45
+ };
46
+ type MiniAppPaymentInitiatedPayload = {
47
+ event: ResponseEvent.MiniAppPaymentInitiated;
48
+ payload: {
49
+ transaction_hash: string;
50
+ status: "completed" | "error";
51
+ chain: string;
52
+ nonce?: string;
53
+ timestamp: string;
54
+ error_code?: string;
55
+ error_message?: string;
56
+ };
57
+ };
58
+ type MiniAppPaymentCompletedPayload = {
59
+ event: ResponseEvent.MiniAppPaymentCompleted;
60
+ payload: {
61
+ transaction_hash: string;
62
+ "status:": "completed" | "error";
63
+ chain: string;
64
+ nonce?: string;
65
+ timestamp: string;
66
+ error_code?: string;
67
+ error_message?: string;
68
+ };
69
+ };
70
+ type EventPayload<T extends ResponseEvent = ResponseEvent> = T extends ResponseEvent.MiniAppVerifyAction ? MiniAppVerifyActionPayload : T extends ResponseEvent.MiniAppPaymentInitiated ? MiniAppPaymentInitiatedPayload : T extends ResponseEvent.MiniAppPaymentCompleted ? MiniAppPaymentCompletedPayload : unknown;
71
+ type EventHandler<E extends ResponseEvent = ResponseEvent> = <T extends EventPayload<E>>(data: T) => void;
72
+
73
+ declare enum Currency {
74
+ WLD = "wld",
75
+ ETH = "eth",
76
+ USDC = "usdc"
77
+ }
78
+ declare enum Network {
79
+ Optimism = "optimism"
80
+ }
81
+
82
+ declare class MiniKit {
83
+ private static appId;
84
+ private static listeners;
85
+ static subscribe<E extends ResponseEvent>(event: E, handler: EventHandler<E>): void;
86
+ static unsubscribe(event: ResponseEvent): void;
87
+ static trigger(event: ResponseEvent, payload: EventPayload): void;
88
+ static install({ app_id }: {
89
+ app_id: `app_${string}`;
90
+ }): {
91
+ success: boolean;
92
+ error: unknown;
93
+ } | {
94
+ success: boolean;
95
+ error?: undefined;
96
+ };
97
+ static isInstalled(): boolean;
98
+ static commands: {
99
+ verify: (payload: VerifyCommandInput) => void;
100
+ pay: (payload: PayCommandInput) => void;
101
+ closeWebview: () => void;
102
+ };
103
+ }
104
+
105
+ export { Command, Currency, type MiniAppPaymentCompletedPayload, type MiniAppPaymentInitiatedPayload, type MiniAppVerifyActionPayload, MiniKit, Network, type PayCommandInput, ResponseEvent, type VerifyCommandInput, type WebViewBasePayload };
package/build/index.js ADDED
@@ -0,0 +1,105 @@
1
+ // helpers/send-webview-event.ts
2
+ var sendWebviewEvent = (payload) => {
3
+ if (window.webkit) {
4
+ window.webkit?.messageHandlers?.minikit?.postMessage?.(payload);
5
+ } else if (window.Android) {
6
+ window.Android.minikit?.()?.sendEvent?.(JSON.stringify(payload));
7
+ }
8
+ };
9
+
10
+ // types/commands.ts
11
+ var Command = /* @__PURE__ */ ((Command2) => {
12
+ Command2["Verify"] = "verify";
13
+ Command2["Pay"] = "pay";
14
+ return Command2;
15
+ })(Command || {});
16
+
17
+ // types/responses.ts
18
+ var ResponseEvent = /* @__PURE__ */ ((ResponseEvent2) => {
19
+ ResponseEvent2["MiniAppVerifyAction"] = "miniapp-verify-action";
20
+ ResponseEvent2["MiniAppPaymentInitiated"] = "miniapp-payment-initiated";
21
+ ResponseEvent2["MiniAppPaymentCompleted"] = "miniapp-payment-completed";
22
+ return ResponseEvent2;
23
+ })(ResponseEvent || {});
24
+
25
+ // types/payment.ts
26
+ var Currency = /* @__PURE__ */ ((Currency2) => {
27
+ Currency2["WLD"] = "wld";
28
+ Currency2["ETH"] = "eth";
29
+ Currency2["USDC"] = "usdc";
30
+ return Currency2;
31
+ })(Currency || {});
32
+ var Network = /* @__PURE__ */ ((Network2) => {
33
+ Network2["Optimism"] = "optimism";
34
+ return Network2;
35
+ })(Network || {});
36
+
37
+ // minikit.ts
38
+ var sendMiniKitEvent = (payload) => {
39
+ sendWebviewEvent(payload);
40
+ };
41
+ var _MiniKit = class _MiniKit {
42
+ static subscribe(event, handler) {
43
+ this.listeners[event] = handler;
44
+ }
45
+ static unsubscribe(event) {
46
+ delete this.listeners[event];
47
+ }
48
+ static trigger(event, payload) {
49
+ if (!this.listeners[event]) {
50
+ return;
51
+ }
52
+ this.listeners[event](payload);
53
+ }
54
+ static install({ app_id }) {
55
+ this.appId = app_id;
56
+ if (typeof window !== "undefined" && !Boolean(window.MiniKit)) {
57
+ try {
58
+ window.MiniKit = _MiniKit;
59
+ } catch (error) {
60
+ console.error("Failed to install MiniKit", error);
61
+ return { success: false, error };
62
+ }
63
+ }
64
+ return { success: true };
65
+ }
66
+ static isInstalled() {
67
+ console.log("MiniKit is alive!");
68
+ return true;
69
+ }
70
+ };
71
+ _MiniKit.listeners = {
72
+ ["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
73
+ },
74
+ ["miniapp-payment-initiated" /* MiniAppPaymentInitiated */]: () => {
75
+ },
76
+ ["miniapp-payment-completed" /* MiniAppPaymentCompleted */]: () => {
77
+ }
78
+ };
79
+ _MiniKit.commands = {
80
+ verify: (payload) => {
81
+ sendMiniKitEvent({ command: "verify" /* Verify */, payload });
82
+ },
83
+ pay: (payload) => {
84
+ sendMiniKitEvent({
85
+ command: "pay" /* Pay */,
86
+ app_id: _MiniKit.appId,
87
+ payload
88
+ });
89
+ },
90
+ closeWebview: () => {
91
+ sendWebviewEvent({ command: "close" });
92
+ }
93
+ };
94
+ var MiniKit = _MiniKit;
95
+
96
+ // index.ts
97
+ import { VerificationLevel } from "@worldcoin/idkit-core";
98
+ export {
99
+ Command,
100
+ Currency,
101
+ MiniKit,
102
+ Network,
103
+ ResponseEvent,
104
+ VerificationLevel
105
+ };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@worldcoin/minikit-js",
3
+ "version": "0.0.1",
4
+ "homepage": "https://docs.worldcoin.org/id/minikit",
5
+ "description": "Alpha version (not ready): Mini-kit JS is a lightweight sdk for building mini-apps compatible with World ID",
6
+ "license": "MIT",
7
+ "private": false,
8
+ "type": "module",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./build/index.js",
12
+ "types": "./build/index.d.ts",
13
+ "require": "./build/index.cjs"
14
+ }
15
+ },
16
+ "engines": {
17
+ "node": ">=12.4"
18
+ },
19
+ "files": [
20
+ "./build/**",
21
+ "README.md"
22
+ ],
23
+ "keywords": [
24
+ "minikit",
25
+ "miniapps"
26
+ ],
27
+ "dependencies": {
28
+ "@worldcoin/idkit-core": "^1.2.0",
29
+ "react": "^18"
30
+ },
31
+ "devDependencies": {
32
+ "@typescript-eslint/eslint-plugin": "^7.7.0",
33
+ "@typescript-eslint/parser": "^7.7.0",
34
+ "prettier": "^3.2.5",
35
+ "prettier-plugin-sort-imports-desc": "^1.0.0",
36
+ "tsup": "^8.0.2",
37
+ "turbo": "^1.13.2",
38
+ "typescript": "^5.4.5"
39
+ },
40
+ "scripts": {
41
+ "build": "tsup",
42
+ "dev": "tsup --watch",
43
+ "lint": "eslint ./ --ext .ts"
44
+ }
45
+ }