@worldcoin/minikit-js 0.0.1 → 0.0.2

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,185 @@
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
+ reference: string;
87
+ from: string;
88
+ chain: Network;
89
+ timestamp: string;
90
+ };
91
+ type MiniAppPaymentErrorPayload = {
92
+ status: "error";
93
+ error_code: PaymentErrorCodes;
94
+ };
95
+ type MiniAppPaymentPayload = MiniAppPaymentSuccessEventPayload | MiniAppPaymentErrorPayload;
96
+ type MiniAppWalletAuthSuccessPayload = {
97
+ status: "success";
98
+ message: string;
99
+ signature: string;
100
+ address: string;
69
101
  };
70
- type EventPayload<T extends ResponseEvent = ResponseEvent> = T extends ResponseEvent.MiniAppVerifyAction ? MiniAppVerifyActionPayload : T extends ResponseEvent.MiniAppPaymentInitiated ? MiniAppPaymentInitiatedPayload : T extends ResponseEvent.MiniAppPaymentCompleted ? MiniAppPaymentCompletedPayload : unknown;
102
+ type MiniAppWalletAuthErrorPayload = {
103
+ status: "error";
104
+ error_code: WalletAuthErrorCodes;
105
+ details: (typeof WalletAuthErrorMessage)[WalletAuthErrorCodes];
106
+ };
107
+ type EventPayload<T extends ResponseEvent = ResponseEvent> = T extends ResponseEvent.MiniAppVerifyAction ? MiniAppVerifyActionPayload : MiniAppPaymentPayload;
71
108
  type EventHandler<E extends ResponseEvent = ResponseEvent> = <T extends EventPayload<E>>(data: T) => void;
72
109
 
73
- declare enum Currency {
74
- WLD = "wld",
75
- ETH = "eth",
76
- USDC = "usdc"
77
- }
78
- declare enum Network {
79
- Optimism = "optimism"
110
+ declare const parseSiweMessage: (inputString: string) => SiweMessage;
111
+ declare const SAFE_CONTRACT_ABI: {
112
+ name: string;
113
+ type: string;
114
+ stateMutability: string;
115
+ inputs: {
116
+ name: string;
117
+ type: string;
118
+ }[];
119
+ outputs: never[];
120
+ }[];
121
+ declare const verifySiweMessage: (payload: MiniAppWalletAuthSuccessPayload, nonce: string, statement?: string, requestId?: string, userProvider?: ethers.Provider) => Promise<{
122
+ isValid: boolean;
123
+ siweMessageData: SiweMessage;
124
+ }>;
125
+ declare const generateNonce: () => string;
126
+
127
+ declare enum Command {
128
+ Verify = "verify",
129
+ Pay = "pay",
130
+ WalletAuth = "wallet-auth"
80
131
  }
132
+ type VerifyCommandInput = {
133
+ action: IDKitConfig["action"];
134
+ signal?: IDKitConfig["signal"];
135
+ verification_level?: VerificationLevel$1;
136
+ };
137
+ type PayCommandInput = {
138
+ reference: string;
139
+ to: string;
140
+ token_amount: number;
141
+ token: Tokens;
142
+ network?: Network;
143
+ description: string;
144
+ };
145
+ type WalletAuthInput = {
146
+ nonce: string;
147
+ statement?: string;
148
+ requestId?: string;
149
+ expirationTime?: Date;
150
+ notBefore?: Date;
151
+ };
152
+ type VerifyCommandPayload = VerifyCommandInput & {
153
+ timestamp: string;
154
+ };
155
+ type PayCommandPayload = PayCommandInput & {
156
+ reference: string;
157
+ };
158
+ type WalletAuthPayload = {
159
+ siweMessage: string;
160
+ };
81
161
 
82
162
  declare class MiniKit {
83
- private static appId;
84
163
  private static listeners;
85
164
  static subscribe<E extends ResponseEvent>(event: E, handler: EventHandler<E>): void;
86
165
  static unsubscribe(event: ResponseEvent): void;
87
166
  static trigger(event: ResponseEvent, payload: EventPayload): void;
88
- static install({ app_id }: {
89
- app_id: `app_${string}`;
90
- }): {
167
+ static install(): {
91
168
  success: boolean;
92
169
  error: unknown;
93
170
  } | {
94
171
  success: boolean;
95
172
  error?: undefined;
96
173
  };
97
- static isInstalled(): boolean;
174
+ static isInstalled(debug?: boolean): boolean;
98
175
  static commands: {
99
- verify: (payload: VerifyCommandInput) => void;
100
- pay: (payload: PayCommandInput) => void;
176
+ verify: (payload: VerifyCommandInput) => VerifyCommandPayload;
177
+ pay: (payload: PayCommandInput) => PayCommandPayload | null;
178
+ walletAuth: (payload: WalletAuthInput) => WalletAuthPayload | null;
101
179
  closeWebview: () => void;
102
180
  };
103
181
  }
104
182
 
105
- export { Command, Currency, type MiniAppPaymentCompletedPayload, type MiniAppPaymentInitiatedPayload, type MiniAppVerifyActionPayload, MiniKit, Network, type PayCommandInput, ResponseEvent, type VerifyCommandInput, type WebViewBasePayload };
183
+ declare const tokenToDecimals: (amount: number, token: Tokens) => number;
184
+
185
+ 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,185 @@
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
+ reference: string;
87
+ from: string;
88
+ chain: Network;
89
+ timestamp: string;
90
+ };
91
+ type MiniAppPaymentErrorPayload = {
92
+ status: "error";
93
+ error_code: PaymentErrorCodes;
94
+ };
95
+ type MiniAppPaymentPayload = MiniAppPaymentSuccessEventPayload | MiniAppPaymentErrorPayload;
96
+ type MiniAppWalletAuthSuccessPayload = {
97
+ status: "success";
98
+ message: string;
99
+ signature: string;
100
+ address: string;
69
101
  };
70
- type EventPayload<T extends ResponseEvent = ResponseEvent> = T extends ResponseEvent.MiniAppVerifyAction ? MiniAppVerifyActionPayload : T extends ResponseEvent.MiniAppPaymentInitiated ? MiniAppPaymentInitiatedPayload : T extends ResponseEvent.MiniAppPaymentCompleted ? MiniAppPaymentCompletedPayload : unknown;
102
+ type MiniAppWalletAuthErrorPayload = {
103
+ status: "error";
104
+ error_code: WalletAuthErrorCodes;
105
+ details: (typeof WalletAuthErrorMessage)[WalletAuthErrorCodes];
106
+ };
107
+ type EventPayload<T extends ResponseEvent = ResponseEvent> = T extends ResponseEvent.MiniAppVerifyAction ? MiniAppVerifyActionPayload : MiniAppPaymentPayload;
71
108
  type EventHandler<E extends ResponseEvent = ResponseEvent> = <T extends EventPayload<E>>(data: T) => void;
72
109
 
73
- declare enum Currency {
74
- WLD = "wld",
75
- ETH = "eth",
76
- USDC = "usdc"
77
- }
78
- declare enum Network {
79
- Optimism = "optimism"
110
+ declare const parseSiweMessage: (inputString: string) => SiweMessage;
111
+ declare const SAFE_CONTRACT_ABI: {
112
+ name: string;
113
+ type: string;
114
+ stateMutability: string;
115
+ inputs: {
116
+ name: string;
117
+ type: string;
118
+ }[];
119
+ outputs: never[];
120
+ }[];
121
+ declare const verifySiweMessage: (payload: MiniAppWalletAuthSuccessPayload, nonce: string, statement?: string, requestId?: string, userProvider?: ethers.Provider) => Promise<{
122
+ isValid: boolean;
123
+ siweMessageData: SiweMessage;
124
+ }>;
125
+ declare const generateNonce: () => string;
126
+
127
+ declare enum Command {
128
+ Verify = "verify",
129
+ Pay = "pay",
130
+ WalletAuth = "wallet-auth"
80
131
  }
132
+ type VerifyCommandInput = {
133
+ action: IDKitConfig["action"];
134
+ signal?: IDKitConfig["signal"];
135
+ verification_level?: VerificationLevel$1;
136
+ };
137
+ type PayCommandInput = {
138
+ reference: string;
139
+ to: string;
140
+ token_amount: number;
141
+ token: Tokens;
142
+ network?: Network;
143
+ description: string;
144
+ };
145
+ type WalletAuthInput = {
146
+ nonce: string;
147
+ statement?: string;
148
+ requestId?: string;
149
+ expirationTime?: Date;
150
+ notBefore?: Date;
151
+ };
152
+ type VerifyCommandPayload = VerifyCommandInput & {
153
+ timestamp: string;
154
+ };
155
+ type PayCommandPayload = PayCommandInput & {
156
+ reference: string;
157
+ };
158
+ type WalletAuthPayload = {
159
+ siweMessage: string;
160
+ };
81
161
 
82
162
  declare class MiniKit {
83
- private static appId;
84
163
  private static listeners;
85
164
  static subscribe<E extends ResponseEvent>(event: E, handler: EventHandler<E>): void;
86
165
  static unsubscribe(event: ResponseEvent): void;
87
166
  static trigger(event: ResponseEvent, payload: EventPayload): void;
88
- static install({ app_id }: {
89
- app_id: `app_${string}`;
90
- }): {
167
+ static install(): {
91
168
  success: boolean;
92
169
  error: unknown;
93
170
  } | {
94
171
  success: boolean;
95
172
  error?: undefined;
96
173
  };
97
- static isInstalled(): boolean;
174
+ static isInstalled(debug?: boolean): boolean;
98
175
  static commands: {
99
- verify: (payload: VerifyCommandInput) => void;
100
- pay: (payload: PayCommandInput) => void;
176
+ verify: (payload: VerifyCommandInput) => VerifyCommandPayload;
177
+ pay: (payload: PayCommandInput) => PayCommandPayload | null;
178
+ walletAuth: (payload: WalletAuthInput) => WalletAuthPayload | null;
101
179
  closeWebview: () => void;
102
180
  };
103
181
  }
104
182
 
105
- export { Command, Currency, type MiniAppPaymentCompletedPayload, type MiniAppPaymentInitiatedPayload, type MiniAppVerifyActionPayload, MiniKit, Network, type PayCommandInput, ResponseEvent, type VerifyCommandInput, type WebViewBasePayload };
183
+ declare const tokenToDecimals: (amount: number, token: Tokens) => number;
184
+
185
+ 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 };