@worldcoin/minikit-js 1.11.0 → 2.0.0-dev.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.
- package/README.md +107 -0
- package/build/address-book.cjs +81 -0
- package/build/address-book.d.cts +3 -0
- package/build/address-book.d.ts +3 -0
- package/build/address-book.js +54 -0
- package/build/chunk-2UPJKPQ6.js +272 -0
- package/build/chunk-EHBM7OXH.js +596 -0
- package/build/chunk-LHHKY77D.js +274 -0
- package/build/chunk-TGXD24YD.js +279 -0
- package/build/chunk-Z2UGRZJ2.js +1635 -0
- package/build/command-exports.cjs +1762 -0
- package/build/command-exports.d.cts +105 -0
- package/build/command-exports.d.ts +105 -0
- package/build/command-exports.js +129 -0
- package/build/connector/index.cjs +2601 -0
- package/build/connector/index.d.cts +55 -0
- package/build/connector/index.d.ts +55 -0
- package/build/connector/index.js +90 -0
- package/build/index.cjs +1634 -1627
- package/build/index.d.cts +143 -671
- package/build/index.d.ts +143 -671
- package/build/index.js +7 -206
- package/build/minikit-provider.cjs +1650 -948
- package/build/minikit-provider.d.cts +2 -1
- package/build/minikit-provider.d.ts +2 -1
- package/build/minikit-provider.js +13 -2
- package/build/provider-DeDUsLbs.d.cts +43 -0
- package/build/provider-DeDUsLbs.d.ts +43 -0
- package/build/siwe-exports.cjs +249 -0
- package/build/siwe-exports.d.cts +10 -0
- package/build/siwe-exports.d.ts +10 -0
- package/build/siwe-exports.js +8 -0
- package/build/types-CC2x79HX.d.ts +525 -0
- package/build/types-CSyzFDPt.d.cts +223 -0
- package/build/types-CSyzFDPt.d.ts +223 -0
- package/build/types-_jfLbcJW.d.cts +525 -0
- package/package.json +73 -11
- package/build/chunk-62NZ34E4.js +0 -2092
- package/index.ts +0 -29
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import {
|
|
3
|
+
setWagmiConfig
|
|
4
|
+
} from "./chunk-2UPJKPQ6.js";
|
|
2
5
|
import {
|
|
3
6
|
MiniKit
|
|
4
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-EHBM7OXH.js";
|
|
8
|
+
import "./chunk-Z2UGRZJ2.js";
|
|
9
|
+
import "./chunk-LHHKY77D.js";
|
|
5
10
|
|
|
6
|
-
// minikit-provider.tsx
|
|
11
|
+
// src/minikit-provider.tsx
|
|
7
12
|
import {
|
|
8
13
|
createContext,
|
|
9
14
|
useContext,
|
|
@@ -21,6 +26,7 @@ var MiniKitProvider = ({
|
|
|
21
26
|
const [isInstalled, setIsInstalled] = useState(
|
|
22
27
|
void 0
|
|
23
28
|
);
|
|
29
|
+
const wagmiConfig = props?.wagmiConfig;
|
|
24
30
|
useEffect(() => {
|
|
25
31
|
const { success } = MiniKit.install(props?.appId);
|
|
26
32
|
if (!success) return setIsInstalled(false);
|
|
@@ -29,6 +35,11 @@ var MiniKitProvider = ({
|
|
|
29
35
|
);
|
|
30
36
|
setIsInstalled(success);
|
|
31
37
|
}, [props?.appId]);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (wagmiConfig) {
|
|
40
|
+
setWagmiConfig(wagmiConfig);
|
|
41
|
+
}
|
|
42
|
+
}, [wagmiConfig]);
|
|
32
43
|
return /* @__PURE__ */ jsx(MiniKitContext.Provider, { value: { isInstalled }, children });
|
|
33
44
|
};
|
|
34
45
|
var useMiniKit = () => {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-contained EIP-1193 Provider for World App
|
|
3
|
+
*
|
|
4
|
+
* Works with any Ethereum library (viem, ethers, wagmi, or raw EIP-1193).
|
|
5
|
+
* Triggers walletAuth on `eth_requestAccounts` and routes all other RPC
|
|
6
|
+
* methods to MiniKit's native commands.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // viem
|
|
11
|
+
* import { createWalletClient, custom } from 'viem';
|
|
12
|
+
* import { getWorldAppProvider } from '@worldcoin/minikit-js';
|
|
13
|
+
* const client = createWalletClient({ transport: custom(getWorldAppProvider()), chain: worldchain });
|
|
14
|
+
*
|
|
15
|
+
* // ethers
|
|
16
|
+
* import { BrowserProvider } from 'ethers';
|
|
17
|
+
* import { getWorldAppProvider } from '@worldcoin/minikit-js';
|
|
18
|
+
* const provider = new BrowserProvider(getWorldAppProvider());
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
type WorldAppProvider = {
|
|
22
|
+
request: (args: {
|
|
23
|
+
method: string;
|
|
24
|
+
params?: unknown;
|
|
25
|
+
}) => Promise<unknown>;
|
|
26
|
+
on: (event: string, fn: (...args: unknown[]) => void) => void;
|
|
27
|
+
removeListener: (event: string, fn: (...args: unknown[]) => void) => void;
|
|
28
|
+
};
|
|
29
|
+
declare global {
|
|
30
|
+
interface Window {
|
|
31
|
+
__worldapp_eip1193_provider__?: WorldAppProvider;
|
|
32
|
+
__worldapp_eip1193_address__?: `0x${string}`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get the EIP-1193 provider for World App.
|
|
37
|
+
*
|
|
38
|
+
* Returns a singleton instance (stored on `window`) so all consumers
|
|
39
|
+
* share the same provider and address state, even across separate bundles.
|
|
40
|
+
*/
|
|
41
|
+
declare function getWorldAppProvider(): WorldAppProvider;
|
|
42
|
+
|
|
43
|
+
export { type WorldAppProvider as W, getWorldAppProvider as g };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-contained EIP-1193 Provider for World App
|
|
3
|
+
*
|
|
4
|
+
* Works with any Ethereum library (viem, ethers, wagmi, or raw EIP-1193).
|
|
5
|
+
* Triggers walletAuth on `eth_requestAccounts` and routes all other RPC
|
|
6
|
+
* methods to MiniKit's native commands.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // viem
|
|
11
|
+
* import { createWalletClient, custom } from 'viem';
|
|
12
|
+
* import { getWorldAppProvider } from '@worldcoin/minikit-js';
|
|
13
|
+
* const client = createWalletClient({ transport: custom(getWorldAppProvider()), chain: worldchain });
|
|
14
|
+
*
|
|
15
|
+
* // ethers
|
|
16
|
+
* import { BrowserProvider } from 'ethers';
|
|
17
|
+
* import { getWorldAppProvider } from '@worldcoin/minikit-js';
|
|
18
|
+
* const provider = new BrowserProvider(getWorldAppProvider());
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
type WorldAppProvider = {
|
|
22
|
+
request: (args: {
|
|
23
|
+
method: string;
|
|
24
|
+
params?: unknown;
|
|
25
|
+
}) => Promise<unknown>;
|
|
26
|
+
on: (event: string, fn: (...args: unknown[]) => void) => void;
|
|
27
|
+
removeListener: (event: string, fn: (...args: unknown[]) => void) => void;
|
|
28
|
+
};
|
|
29
|
+
declare global {
|
|
30
|
+
interface Window {
|
|
31
|
+
__worldapp_eip1193_provider__?: WorldAppProvider;
|
|
32
|
+
__worldapp_eip1193_address__?: `0x${string}`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get the EIP-1193 provider for World App.
|
|
37
|
+
*
|
|
38
|
+
* Returns a singleton instance (stored on `window`) so all consumers
|
|
39
|
+
* share the same provider and address state, even across separate bundles.
|
|
40
|
+
*/
|
|
41
|
+
declare function getWorldAppProvider(): WorldAppProvider;
|
|
42
|
+
|
|
43
|
+
export { type WorldAppProvider as W, getWorldAppProvider as g };
|
|
@@ -0,0 +1,249 @@
|
|
|
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
|
+
// src/siwe-exports.ts
|
|
21
|
+
var siwe_exports_exports = {};
|
|
22
|
+
__export(siwe_exports_exports, {
|
|
23
|
+
parseSiweMessage: () => parseSiweMessage,
|
|
24
|
+
verifySiweMessage: () => verifySiweMessage
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(siwe_exports_exports);
|
|
27
|
+
|
|
28
|
+
// src/commands/wallet-auth/siwe.ts
|
|
29
|
+
var import_viem = require("viem");
|
|
30
|
+
var import_chains = require("viem/chains");
|
|
31
|
+
var PREAMBLE = " wants you to sign in with your Ethereum account:";
|
|
32
|
+
var URI_TAG = "URI: ";
|
|
33
|
+
var VERSION_TAG = "Version: ";
|
|
34
|
+
var CHAIN_TAG = "Chain ID: ";
|
|
35
|
+
var NONCE_TAG = "Nonce: ";
|
|
36
|
+
var IAT_TAG = "Issued At: ";
|
|
37
|
+
var EXP_TAG = "Expiration Time: ";
|
|
38
|
+
var NBF_TAG = "Not Before: ";
|
|
39
|
+
var RID_TAG = "Request ID: ";
|
|
40
|
+
var ERC_191_PREFIX = "Ethereum Signed Message:\n";
|
|
41
|
+
var EIP1271_MAGICVALUE = "0x1626ba7e";
|
|
42
|
+
var SAFE_CONTRACT_ABI = [
|
|
43
|
+
{
|
|
44
|
+
inputs: [
|
|
45
|
+
{
|
|
46
|
+
internalType: "address",
|
|
47
|
+
name: "owner",
|
|
48
|
+
type: "address"
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
name: "isOwner",
|
|
52
|
+
outputs: [
|
|
53
|
+
{
|
|
54
|
+
internalType: "bool",
|
|
55
|
+
name: "",
|
|
56
|
+
type: "bool"
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
stateMutability: "view",
|
|
60
|
+
type: "function"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
inputs: [
|
|
64
|
+
{
|
|
65
|
+
internalType: "bytes32",
|
|
66
|
+
name: "_message",
|
|
67
|
+
type: "bytes32"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
internalType: "bytes",
|
|
71
|
+
name: "_signature",
|
|
72
|
+
type: "bytes"
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
name: "isValidSignature",
|
|
76
|
+
outputs: [
|
|
77
|
+
{
|
|
78
|
+
internalType: "bytes4",
|
|
79
|
+
name: "",
|
|
80
|
+
type: "bytes4"
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
stateMutability: "view",
|
|
84
|
+
type: "function"
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
var tagged = (line, tag) => {
|
|
88
|
+
if (line && line.includes(tag)) {
|
|
89
|
+
return line.replace(tag, "");
|
|
90
|
+
} else {
|
|
91
|
+
throw new Error(`Missing '${tag}'`);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
var parseSiweMessage = (inputString) => {
|
|
95
|
+
const lines = inputString.split("\n")[Symbol.iterator]();
|
|
96
|
+
const domain = tagged(lines.next()?.value, PREAMBLE);
|
|
97
|
+
const address = lines.next()?.value;
|
|
98
|
+
lines.next();
|
|
99
|
+
const nextValue = lines.next()?.value;
|
|
100
|
+
let statement;
|
|
101
|
+
if (nextValue) {
|
|
102
|
+
statement = nextValue;
|
|
103
|
+
lines.next();
|
|
104
|
+
}
|
|
105
|
+
const uri = tagged(lines.next()?.value, URI_TAG);
|
|
106
|
+
const version = tagged(lines.next()?.value, VERSION_TAG);
|
|
107
|
+
const chain_id = tagged(lines.next()?.value, CHAIN_TAG);
|
|
108
|
+
const nonce = tagged(lines.next()?.value, NONCE_TAG);
|
|
109
|
+
const issued_at = tagged(lines.next()?.value, IAT_TAG);
|
|
110
|
+
let expiration_time, not_before, request_id;
|
|
111
|
+
for (let line of lines) {
|
|
112
|
+
if (line.startsWith(EXP_TAG)) {
|
|
113
|
+
expiration_time = tagged(line, EXP_TAG);
|
|
114
|
+
} else if (line.startsWith(NBF_TAG)) {
|
|
115
|
+
not_before = tagged(line, NBF_TAG);
|
|
116
|
+
} else if (line.startsWith(RID_TAG)) {
|
|
117
|
+
request_id = tagged(line, RID_TAG);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (lines.next().done === false) {
|
|
121
|
+
throw new Error("Extra lines in the input");
|
|
122
|
+
}
|
|
123
|
+
const siweMessageData = {
|
|
124
|
+
domain,
|
|
125
|
+
address,
|
|
126
|
+
statement,
|
|
127
|
+
uri,
|
|
128
|
+
version,
|
|
129
|
+
chain_id,
|
|
130
|
+
nonce,
|
|
131
|
+
issued_at,
|
|
132
|
+
expiration_time,
|
|
133
|
+
not_before,
|
|
134
|
+
request_id
|
|
135
|
+
};
|
|
136
|
+
return siweMessageData;
|
|
137
|
+
};
|
|
138
|
+
var verifySiweMessage = (payload, nonce, statement, requestId, userProvider) => {
|
|
139
|
+
if (payload.version === 1) {
|
|
140
|
+
return verifySiweMessageV1(
|
|
141
|
+
payload,
|
|
142
|
+
nonce,
|
|
143
|
+
statement,
|
|
144
|
+
requestId,
|
|
145
|
+
userProvider
|
|
146
|
+
);
|
|
147
|
+
} else {
|
|
148
|
+
return verifySiweMessageV2(
|
|
149
|
+
payload,
|
|
150
|
+
nonce,
|
|
151
|
+
statement,
|
|
152
|
+
requestId,
|
|
153
|
+
userProvider
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
var validateMessage = (siweMessageData, nonce, statement, requestId) => {
|
|
158
|
+
if (siweMessageData.expiration_time) {
|
|
159
|
+
const expirationTime = new Date(siweMessageData.expiration_time);
|
|
160
|
+
if (expirationTime < /* @__PURE__ */ new Date()) {
|
|
161
|
+
throw new Error("Expired message");
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (siweMessageData.not_before) {
|
|
165
|
+
const notBefore = new Date(siweMessageData.not_before);
|
|
166
|
+
if (notBefore > /* @__PURE__ */ new Date()) {
|
|
167
|
+
throw new Error("Not Before time has not passed");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (nonce && siweMessageData.nonce !== nonce) {
|
|
171
|
+
throw new Error(
|
|
172
|
+
`Nonce mismatch. Got: ${siweMessageData.nonce}, Expected: ${nonce}`
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
if (statement && siweMessageData.statement !== statement) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
`Statement mismatch. Got: ${siweMessageData.statement}, Expected: ${statement}`
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
if (requestId && siweMessageData.request_id !== requestId) {
|
|
181
|
+
throw new Error(
|
|
182
|
+
`Request ID mismatch. Got: ${siweMessageData.request_id}, Expected: ${requestId}`
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
return true;
|
|
186
|
+
};
|
|
187
|
+
var verifySiweMessageV1 = async (payload, nonce, statement, requestId, userProvider) => {
|
|
188
|
+
if (typeof window !== "undefined") {
|
|
189
|
+
throw new Error("Wallet auth payload can only be verified in the backend");
|
|
190
|
+
}
|
|
191
|
+
const { message, signature, address } = payload;
|
|
192
|
+
const siweMessageData = parseSiweMessage(message);
|
|
193
|
+
validateMessage(siweMessageData, nonce, statement, requestId);
|
|
194
|
+
let provider = userProvider || (0, import_viem.createPublicClient)({ chain: import_chains.worldchain, transport: (0, import_viem.http)() });
|
|
195
|
+
const signedMessage = `${ERC_191_PREFIX}${message.length}${message}`;
|
|
196
|
+
const hashedMessage = (0, import_viem.hashMessage)(signedMessage);
|
|
197
|
+
const contract = (0, import_viem.getContract)({
|
|
198
|
+
address,
|
|
199
|
+
abi: SAFE_CONTRACT_ABI,
|
|
200
|
+
client: provider
|
|
201
|
+
});
|
|
202
|
+
try {
|
|
203
|
+
const recoveredAddress = await (0, import_viem.recoverAddress)({
|
|
204
|
+
hash: hashedMessage,
|
|
205
|
+
signature: `0x${signature}`
|
|
206
|
+
});
|
|
207
|
+
const isOwner = await contract.read.isOwner([recoveredAddress]);
|
|
208
|
+
if (!isOwner) {
|
|
209
|
+
throw new Error("Signature verification failed, invalid owner");
|
|
210
|
+
}
|
|
211
|
+
} catch (error) {
|
|
212
|
+
throw new Error("Signature verification failed");
|
|
213
|
+
}
|
|
214
|
+
return { isValid: true, siweMessageData };
|
|
215
|
+
};
|
|
216
|
+
var verifySiweMessageV2 = async (payload, nonce, statement, requestId, userProvider) => {
|
|
217
|
+
if (typeof window !== "undefined") {
|
|
218
|
+
throw new Error("Wallet auth payload can only be verified in the backend");
|
|
219
|
+
}
|
|
220
|
+
const { message, signature, address } = payload;
|
|
221
|
+
const siweMessageData = parseSiweMessage(message);
|
|
222
|
+
if (!validateMessage(siweMessageData, nonce, statement, requestId)) {
|
|
223
|
+
throw new Error("Validation failed");
|
|
224
|
+
}
|
|
225
|
+
try {
|
|
226
|
+
const walletContract = (0, import_viem.getContract)({
|
|
227
|
+
address,
|
|
228
|
+
abi: SAFE_CONTRACT_ABI,
|
|
229
|
+
client: userProvider || (0, import_viem.createPublicClient)({ chain: import_chains.worldchain, transport: (0, import_viem.http)() })
|
|
230
|
+
});
|
|
231
|
+
const hashedMessage = (0, import_viem.hashMessage)(message);
|
|
232
|
+
const res = await walletContract.read.isValidSignature([
|
|
233
|
+
hashedMessage,
|
|
234
|
+
signature
|
|
235
|
+
]);
|
|
236
|
+
return {
|
|
237
|
+
isValid: res === EIP1271_MAGICVALUE,
|
|
238
|
+
siweMessageData
|
|
239
|
+
};
|
|
240
|
+
} catch (error) {
|
|
241
|
+
console.log(error);
|
|
242
|
+
throw new Error("Signature verification failed");
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
246
|
+
0 && (module.exports = {
|
|
247
|
+
parseSiweMessage,
|
|
248
|
+
verifySiweMessage
|
|
249
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Client } from 'viem';
|
|
2
|
+
import { S as SiweMessage, y as MiniAppWalletAuthSuccessPayload } from './types-CSyzFDPt.cjs';
|
|
3
|
+
|
|
4
|
+
declare const parseSiweMessage: (inputString: string) => SiweMessage;
|
|
5
|
+
declare const verifySiweMessage: (payload: MiniAppWalletAuthSuccessPayload, nonce: string, statement?: string, requestId?: string, userProvider?: Client) => Promise<{
|
|
6
|
+
isValid: boolean;
|
|
7
|
+
siweMessageData: SiweMessage;
|
|
8
|
+
}>;
|
|
9
|
+
|
|
10
|
+
export { parseSiweMessage, verifySiweMessage };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Client } from 'viem';
|
|
2
|
+
import { S as SiweMessage, y as MiniAppWalletAuthSuccessPayload } from './types-CSyzFDPt.js';
|
|
3
|
+
|
|
4
|
+
declare const parseSiweMessage: (inputString: string) => SiweMessage;
|
|
5
|
+
declare const verifySiweMessage: (payload: MiniAppWalletAuthSuccessPayload, nonce: string, statement?: string, requestId?: string, userProvider?: Client) => Promise<{
|
|
6
|
+
isValid: boolean;
|
|
7
|
+
siweMessageData: SiweMessage;
|
|
8
|
+
}>;
|
|
9
|
+
|
|
10
|
+
export { parseSiweMessage, verifySiweMessage };
|