@worldcoin/minikit-js 0.0.1 → 0.0.2-internal-alpha

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/build/index.d.cts CHANGED
@@ -1,105 +1,186 @@
1
- import { VerificationLevel } from '@worldcoin/idkit-core';
2
- export { VerificationLevel } from '@worldcoin/idkit-core';
1
+ import { ethers } from 'ethers';
2
+ import { AppErrorCodes, VerificationLevel } from '@worldcoin/idkit-core';
3
+ export { AppErrorCodes as VerificationErrorCodes, VerificationLevel } from '@worldcoin/idkit-core';
4
+ import { IDKitConfig, VerificationLevel as VerificationLevel$1 } from '@worldcoin/idkit-core/*';
3
5
 
4
- declare enum Command {
5
- Verify = "verify",
6
- Pay = "pay"
7
- }
8
- type WebViewBasePayload = {
9
- command: Command;
10
- payload: Record<string, any>;
6
+ type SiweMessage = {
7
+ scheme?: string;
8
+ domain: string;
9
+ address?: string;
10
+ statement?: string;
11
+ uri: string;
12
+ version: number;
13
+ chain_id: number;
14
+ nonce: string;
15
+ issued_at: string;
16
+ expiration_time?: string;
17
+ not_before?: string;
18
+ request_id?: string;
11
19
  };
12
- type VerifyCommandInput = {
13
- app_id: `app_${string}`;
14
- action: string;
15
- signal: string;
16
- verification_level: string;
17
- timestamp: string;
20
+
21
+ declare enum Tokens {
22
+ USDC = "USDC",
23
+ WLD = "WLD"
24
+ }
25
+ declare const TokenDecimals: {
26
+ [key in Tokens]: number;
18
27
  };
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;
28
+ declare enum Network {
29
+ Optimism = "optimism"
30
+ }
31
+
32
+ declare const VerificationErrorMessage: Record<AppErrorCodes, string>;
33
+ declare enum PaymentErrorCodes {
34
+ MalformedRequest = "malformed_request",
35
+ PaymentRejected = "payment_rejected",
36
+ InvalidReceiver = "invalid_receiver",
37
+ InsufficientBalance = "insufficient_balance",
38
+ TransactionFailed = "transaction_failed",
39
+ InvalidTokenAddress = "invalid_token_address",
40
+ InvalidAppId = "invalid_app_id",
41
+ GenericError = "generic_error",
42
+ DuplicateReference = "duplicate_reference"
43
+ }
44
+ declare enum PaymentErrorMessage {
45
+ MalformedRequest = "There was a problem with this request. Please try again or contact the app owner.",
46
+ PaymentRejected = "You\u2019ve cancelled the payment in World App.",
47
+ InvalidReceiver = "The receiver address is invalid. Please contact the app owner.",
48
+ InsufficientBalance = "You do not have enough balance to complete this transaction.",
49
+ TransactionFailed = "The transaction failed. Please try again.",
50
+ InvalidTokenAddress = "The token address is invalid. Please contact the app owner.",
51
+ InvalidAppId = "The app ID is invalid. Please contact the app owner.",
52
+ GenericError = "Something unexpected went wrong. Please try again.",
53
+ DuplicateReference = "This reference ID already exists please generate a new one and try again."
54
+ }
55
+ declare enum WalletAuthErrorCodes {
56
+ InvalidAddress = "invalid_address",
57
+ MalformedRequest = "malformed_request",
58
+ UserRejected = "user_rejected"
59
+ }
60
+ declare const WalletAuthErrorMessage: {
61
+ invalid_address: string;
62
+ malformed_request: string;
63
+ user_rejected: string;
27
64
  };
28
65
 
29
66
  declare enum ResponseEvent {
30
67
  MiniAppVerifyAction = "miniapp-verify-action",
31
- MiniAppPaymentInitiated = "miniapp-payment-initiated",
32
- MiniAppPaymentCompleted = "miniapp-payment-completed"
68
+ MiniAppPayment = "miniapp-payment",
69
+ MiniAppWalletAuth = "miniapp-wallet-auth"
33
70
  }
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
- };
71
+ type MiniAppVerifyActionSuccessPayload = {
72
+ status: "success";
73
+ proof: string;
74
+ merkle_root: string;
75
+ nullifier_hash: string;
76
+ verification_level: VerificationLevel;
45
77
  };
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
- };
78
+ type MiniAppVerifyActionErrorPayload = {
79
+ status: "error";
80
+ error_code: AppErrorCodes;
57
81
  };
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
- };
82
+ type MiniAppVerifyActionPayload = MiniAppVerifyActionSuccessPayload | MiniAppVerifyActionErrorPayload;
83
+ type MiniAppPaymentSuccessEventPayload = {
84
+ status: "success";
85
+ transaction_status: "submitted";
86
+ transaction_id: string;
87
+ reference: string;
88
+ from: string;
89
+ chain: Network;
90
+ timestamp: string;
91
+ };
92
+ type MiniAppPaymentErrorPayload = {
93
+ status: "error";
94
+ error_code: PaymentErrorCodes;
95
+ };
96
+ type MiniAppPaymentPayload = MiniAppPaymentSuccessEventPayload | MiniAppPaymentErrorPayload;
97
+ type MiniAppWalletAuthSuccessPayload = {
98
+ status: "success";
99
+ message: string;
100
+ signature: string;
101
+ address: string;
69
102
  };
70
- type EventPayload<T extends ResponseEvent = ResponseEvent> = T extends ResponseEvent.MiniAppVerifyAction ? MiniAppVerifyActionPayload : T extends ResponseEvent.MiniAppPaymentInitiated ? MiniAppPaymentInitiatedPayload : T extends ResponseEvent.MiniAppPaymentCompleted ? MiniAppPaymentCompletedPayload : unknown;
103
+ type MiniAppWalletAuthErrorPayload = {
104
+ status: "error";
105
+ error_code: WalletAuthErrorCodes;
106
+ details: (typeof WalletAuthErrorMessage)[WalletAuthErrorCodes];
107
+ };
108
+ type EventPayload<T extends ResponseEvent = ResponseEvent> = T extends ResponseEvent.MiniAppVerifyAction ? MiniAppVerifyActionPayload : MiniAppPaymentPayload;
71
109
  type EventHandler<E extends ResponseEvent = ResponseEvent> = <T extends EventPayload<E>>(data: T) => void;
72
110
 
73
- declare enum Currency {
74
- WLD = "wld",
75
- ETH = "eth",
76
- USDC = "usdc"
77
- }
78
- declare enum Network {
79
- Optimism = "optimism"
111
+ declare const parseSiweMessage: (inputString: string) => SiweMessage;
112
+ declare const SAFE_CONTRACT_ABI: {
113
+ name: string;
114
+ type: string;
115
+ stateMutability: string;
116
+ inputs: {
117
+ name: string;
118
+ type: string;
119
+ }[];
120
+ outputs: never[];
121
+ }[];
122
+ declare const verifySiweMessage: (payload: MiniAppWalletAuthSuccessPayload, nonce: string, statement?: string, requestId?: string, userProvider?: ethers.Provider) => Promise<{
123
+ isValid: boolean;
124
+ siweMessageData: SiweMessage;
125
+ }>;
126
+ declare const generateNonce: () => string;
127
+
128
+ declare enum Command {
129
+ Verify = "verify",
130
+ Pay = "pay",
131
+ WalletAuth = "wallet-auth"
80
132
  }
133
+ type VerifyCommandInput = {
134
+ action: IDKitConfig["action"];
135
+ signal?: IDKitConfig["signal"];
136
+ verification_level?: VerificationLevel$1;
137
+ };
138
+ type PayCommandInput = {
139
+ reference: string;
140
+ to: string;
141
+ token_amount: number;
142
+ token: Tokens;
143
+ network?: Network;
144
+ description: string;
145
+ };
146
+ type WalletAuthInput = {
147
+ nonce: string;
148
+ statement?: string;
149
+ requestId?: string;
150
+ expirationTime?: Date;
151
+ notBefore?: Date;
152
+ };
153
+ type VerifyCommandPayload = VerifyCommandInput & {
154
+ timestamp: string;
155
+ };
156
+ type PayCommandPayload = PayCommandInput & {
157
+ reference: string;
158
+ };
159
+ type WalletAuthPayload = {
160
+ siweMessage: string;
161
+ };
81
162
 
82
163
  declare class MiniKit {
83
- private static appId;
84
164
  private static listeners;
85
165
  static subscribe<E extends ResponseEvent>(event: E, handler: EventHandler<E>): void;
86
166
  static unsubscribe(event: ResponseEvent): void;
87
167
  static trigger(event: ResponseEvent, payload: EventPayload): void;
88
- static install({ app_id }: {
89
- app_id: `app_${string}`;
90
- }): {
168
+ static install(): {
91
169
  success: boolean;
92
170
  error: unknown;
93
171
  } | {
94
172
  success: boolean;
95
173
  error?: undefined;
96
174
  };
97
- static isInstalled(): boolean;
175
+ static isInstalled(debug?: boolean): boolean;
98
176
  static commands: {
99
- verify: (payload: VerifyCommandInput) => void;
100
- pay: (payload: PayCommandInput) => void;
177
+ verify: (payload: VerifyCommandInput) => VerifyCommandPayload;
178
+ pay: (payload: PayCommandInput) => PayCommandPayload | null;
179
+ walletAuth: (payload: WalletAuthInput) => WalletAuthPayload | null;
101
180
  closeWebview: () => void;
102
181
  };
103
182
  }
104
183
 
105
- export { Command, Currency, type MiniAppPaymentCompletedPayload, type MiniAppPaymentInitiatedPayload, type MiniAppVerifyActionPayload, MiniKit, Network, type PayCommandInput, ResponseEvent, type VerifyCommandInput, type WebViewBasePayload };
184
+ declare const tokenToDecimals: (amount: number, token: Tokens) => number;
185
+
186
+ export { Command, type MiniAppPaymentErrorPayload, type MiniAppPaymentPayload, type MiniAppPaymentSuccessEventPayload, type MiniAppVerifyActionErrorPayload, type MiniAppVerifyActionPayload, type MiniAppVerifyActionSuccessPayload, type MiniAppWalletAuthErrorPayload, type MiniAppWalletAuthSuccessPayload, MiniKit, Network, type PayCommandInput, PaymentErrorCodes, PaymentErrorMessage, ResponseEvent, SAFE_CONTRACT_ABI, type SiweMessage, TokenDecimals, Tokens, VerificationErrorMessage, type VerifyCommandInput, WalletAuthErrorCodes, WalletAuthErrorMessage, generateNonce, parseSiweMessage, tokenToDecimals, verifySiweMessage };
package/build/index.d.ts CHANGED
@@ -1,105 +1,186 @@
1
- import { VerificationLevel } from '@worldcoin/idkit-core';
2
- export { VerificationLevel } from '@worldcoin/idkit-core';
1
+ import { ethers } from 'ethers';
2
+ import { AppErrorCodes, VerificationLevel } from '@worldcoin/idkit-core';
3
+ export { AppErrorCodes as VerificationErrorCodes, VerificationLevel } from '@worldcoin/idkit-core';
4
+ import { IDKitConfig, VerificationLevel as VerificationLevel$1 } from '@worldcoin/idkit-core/*';
3
5
 
4
- declare enum Command {
5
- Verify = "verify",
6
- Pay = "pay"
7
- }
8
- type WebViewBasePayload = {
9
- command: Command;
10
- payload: Record<string, any>;
6
+ type SiweMessage = {
7
+ scheme?: string;
8
+ domain: string;
9
+ address?: string;
10
+ statement?: string;
11
+ uri: string;
12
+ version: number;
13
+ chain_id: number;
14
+ nonce: string;
15
+ issued_at: string;
16
+ expiration_time?: string;
17
+ not_before?: string;
18
+ request_id?: string;
11
19
  };
12
- type VerifyCommandInput = {
13
- app_id: `app_${string}`;
14
- action: string;
15
- signal: string;
16
- verification_level: string;
17
- timestamp: string;
20
+
21
+ declare enum Tokens {
22
+ USDC = "USDC",
23
+ WLD = "WLD"
24
+ }
25
+ declare const TokenDecimals: {
26
+ [key in Tokens]: number;
18
27
  };
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;
28
+ declare enum Network {
29
+ Optimism = "optimism"
30
+ }
31
+
32
+ declare const VerificationErrorMessage: Record<AppErrorCodes, string>;
33
+ declare enum PaymentErrorCodes {
34
+ MalformedRequest = "malformed_request",
35
+ PaymentRejected = "payment_rejected",
36
+ InvalidReceiver = "invalid_receiver",
37
+ InsufficientBalance = "insufficient_balance",
38
+ TransactionFailed = "transaction_failed",
39
+ InvalidTokenAddress = "invalid_token_address",
40
+ InvalidAppId = "invalid_app_id",
41
+ GenericError = "generic_error",
42
+ DuplicateReference = "duplicate_reference"
43
+ }
44
+ declare enum PaymentErrorMessage {
45
+ MalformedRequest = "There was a problem with this request. Please try again or contact the app owner.",
46
+ PaymentRejected = "You\u2019ve cancelled the payment in World App.",
47
+ InvalidReceiver = "The receiver address is invalid. Please contact the app owner.",
48
+ InsufficientBalance = "You do not have enough balance to complete this transaction.",
49
+ TransactionFailed = "The transaction failed. Please try again.",
50
+ InvalidTokenAddress = "The token address is invalid. Please contact the app owner.",
51
+ InvalidAppId = "The app ID is invalid. Please contact the app owner.",
52
+ GenericError = "Something unexpected went wrong. Please try again.",
53
+ DuplicateReference = "This reference ID already exists please generate a new one and try again."
54
+ }
55
+ declare enum WalletAuthErrorCodes {
56
+ InvalidAddress = "invalid_address",
57
+ MalformedRequest = "malformed_request",
58
+ UserRejected = "user_rejected"
59
+ }
60
+ declare const WalletAuthErrorMessage: {
61
+ invalid_address: string;
62
+ malformed_request: string;
63
+ user_rejected: string;
27
64
  };
28
65
 
29
66
  declare enum ResponseEvent {
30
67
  MiniAppVerifyAction = "miniapp-verify-action",
31
- MiniAppPaymentInitiated = "miniapp-payment-initiated",
32
- MiniAppPaymentCompleted = "miniapp-payment-completed"
68
+ MiniAppPayment = "miniapp-payment",
69
+ MiniAppWalletAuth = "miniapp-wallet-auth"
33
70
  }
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
- };
71
+ type MiniAppVerifyActionSuccessPayload = {
72
+ status: "success";
73
+ proof: string;
74
+ merkle_root: string;
75
+ nullifier_hash: string;
76
+ verification_level: VerificationLevel;
45
77
  };
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
- };
78
+ type MiniAppVerifyActionErrorPayload = {
79
+ status: "error";
80
+ error_code: AppErrorCodes;
57
81
  };
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
- };
82
+ type MiniAppVerifyActionPayload = MiniAppVerifyActionSuccessPayload | MiniAppVerifyActionErrorPayload;
83
+ type MiniAppPaymentSuccessEventPayload = {
84
+ status: "success";
85
+ transaction_status: "submitted";
86
+ transaction_id: string;
87
+ reference: string;
88
+ from: string;
89
+ chain: Network;
90
+ timestamp: string;
91
+ };
92
+ type MiniAppPaymentErrorPayload = {
93
+ status: "error";
94
+ error_code: PaymentErrorCodes;
95
+ };
96
+ type MiniAppPaymentPayload = MiniAppPaymentSuccessEventPayload | MiniAppPaymentErrorPayload;
97
+ type MiniAppWalletAuthSuccessPayload = {
98
+ status: "success";
99
+ message: string;
100
+ signature: string;
101
+ address: string;
69
102
  };
70
- type EventPayload<T extends ResponseEvent = ResponseEvent> = T extends ResponseEvent.MiniAppVerifyAction ? MiniAppVerifyActionPayload : T extends ResponseEvent.MiniAppPaymentInitiated ? MiniAppPaymentInitiatedPayload : T extends ResponseEvent.MiniAppPaymentCompleted ? MiniAppPaymentCompletedPayload : unknown;
103
+ type MiniAppWalletAuthErrorPayload = {
104
+ status: "error";
105
+ error_code: WalletAuthErrorCodes;
106
+ details: (typeof WalletAuthErrorMessage)[WalletAuthErrorCodes];
107
+ };
108
+ type EventPayload<T extends ResponseEvent = ResponseEvent> = T extends ResponseEvent.MiniAppVerifyAction ? MiniAppVerifyActionPayload : MiniAppPaymentPayload;
71
109
  type EventHandler<E extends ResponseEvent = ResponseEvent> = <T extends EventPayload<E>>(data: T) => void;
72
110
 
73
- declare enum Currency {
74
- WLD = "wld",
75
- ETH = "eth",
76
- USDC = "usdc"
77
- }
78
- declare enum Network {
79
- Optimism = "optimism"
111
+ declare const parseSiweMessage: (inputString: string) => SiweMessage;
112
+ declare const SAFE_CONTRACT_ABI: {
113
+ name: string;
114
+ type: string;
115
+ stateMutability: string;
116
+ inputs: {
117
+ name: string;
118
+ type: string;
119
+ }[];
120
+ outputs: never[];
121
+ }[];
122
+ declare const verifySiweMessage: (payload: MiniAppWalletAuthSuccessPayload, nonce: string, statement?: string, requestId?: string, userProvider?: ethers.Provider) => Promise<{
123
+ isValid: boolean;
124
+ siweMessageData: SiweMessage;
125
+ }>;
126
+ declare const generateNonce: () => string;
127
+
128
+ declare enum Command {
129
+ Verify = "verify",
130
+ Pay = "pay",
131
+ WalletAuth = "wallet-auth"
80
132
  }
133
+ type VerifyCommandInput = {
134
+ action: IDKitConfig["action"];
135
+ signal?: IDKitConfig["signal"];
136
+ verification_level?: VerificationLevel$1;
137
+ };
138
+ type PayCommandInput = {
139
+ reference: string;
140
+ to: string;
141
+ token_amount: number;
142
+ token: Tokens;
143
+ network?: Network;
144
+ description: string;
145
+ };
146
+ type WalletAuthInput = {
147
+ nonce: string;
148
+ statement?: string;
149
+ requestId?: string;
150
+ expirationTime?: Date;
151
+ notBefore?: Date;
152
+ };
153
+ type VerifyCommandPayload = VerifyCommandInput & {
154
+ timestamp: string;
155
+ };
156
+ type PayCommandPayload = PayCommandInput & {
157
+ reference: string;
158
+ };
159
+ type WalletAuthPayload = {
160
+ siweMessage: string;
161
+ };
81
162
 
82
163
  declare class MiniKit {
83
- private static appId;
84
164
  private static listeners;
85
165
  static subscribe<E extends ResponseEvent>(event: E, handler: EventHandler<E>): void;
86
166
  static unsubscribe(event: ResponseEvent): void;
87
167
  static trigger(event: ResponseEvent, payload: EventPayload): void;
88
- static install({ app_id }: {
89
- app_id: `app_${string}`;
90
- }): {
168
+ static install(): {
91
169
  success: boolean;
92
170
  error: unknown;
93
171
  } | {
94
172
  success: boolean;
95
173
  error?: undefined;
96
174
  };
97
- static isInstalled(): boolean;
175
+ static isInstalled(debug?: boolean): boolean;
98
176
  static commands: {
99
- verify: (payload: VerifyCommandInput) => void;
100
- pay: (payload: PayCommandInput) => void;
177
+ verify: (payload: VerifyCommandInput) => VerifyCommandPayload;
178
+ pay: (payload: PayCommandInput) => PayCommandPayload | null;
179
+ walletAuth: (payload: WalletAuthInput) => WalletAuthPayload | null;
101
180
  closeWebview: () => void;
102
181
  };
103
182
  }
104
183
 
105
- export { Command, Currency, type MiniAppPaymentCompletedPayload, type MiniAppPaymentInitiatedPayload, type MiniAppVerifyActionPayload, MiniKit, Network, type PayCommandInput, ResponseEvent, type VerifyCommandInput, type WebViewBasePayload };
184
+ declare const tokenToDecimals: (amount: number, token: Tokens) => number;
185
+
186
+ export { Command, type MiniAppPaymentErrorPayload, type MiniAppPaymentPayload, type MiniAppPaymentSuccessEventPayload, type MiniAppVerifyActionErrorPayload, type MiniAppVerifyActionPayload, type MiniAppVerifyActionSuccessPayload, type MiniAppWalletAuthErrorPayload, type MiniAppWalletAuthSuccessPayload, MiniKit, Network, type PayCommandInput, PaymentErrorCodes, PaymentErrorMessage, ResponseEvent, SAFE_CONTRACT_ABI, type SiweMessage, TokenDecimals, Tokens, VerificationErrorMessage, type VerifyCommandInput, WalletAuthErrorCodes, WalletAuthErrorMessage, generateNonce, parseSiweMessage, tokenToDecimals, verifySiweMessage };