@sign-global/tokentable 0.4.0-beta.1 → 0.4.0-beta.11

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.
Files changed (78) hide show
  1. package/README.md +98 -2
  2. package/dist/cjs/airdrop/AirdropClient.js +9 -2
  3. package/dist/cjs/airdrop/AirdropClient.js.map +1 -1
  4. package/dist/cjs/airdrop/SignatureAirdropClient.d.ts +22 -9
  5. package/dist/cjs/airdrop/SignatureAirdropClient.js +95 -19
  6. package/dist/cjs/airdrop/SignatureAirdropClient.js.map +1 -1
  7. package/dist/cjs/airdrop/core/evm/SignatureAirdropService.d.ts +23 -0
  8. package/dist/cjs/airdrop/core/evm/SignatureAirdropService.js +71 -0
  9. package/dist/cjs/airdrop/core/evm/SignatureAirdropService.js.map +1 -0
  10. package/dist/cjs/airdrop/core/evm/contracts/AirdropSignatureClient.d.ts +16 -0
  11. package/dist/cjs/airdrop/core/evm/contracts/AirdropSignatureClient.js +47 -0
  12. package/dist/cjs/airdrop/core/evm/contracts/AirdropSignatureClient.js.map +1 -0
  13. package/dist/cjs/airdrop/core/evm/contracts/abis/FungibleTokenECDSADistributor.json +564 -0
  14. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.d.ts +1 -1
  15. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js +6 -3
  16. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js.map +1 -1
  17. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/index.d.ts +2 -1
  18. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/index.js +6 -4
  19. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/evm/index.js.map +1 -1
  20. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/solana/index.d.ts +1 -1
  21. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js +10 -11
  22. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js.map +1 -1
  23. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.d.ts +1 -1
  24. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js +10 -9
  25. package/dist/cjs/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js.map +1 -1
  26. package/dist/cjs/airdrop/services/index.d.ts +25 -8
  27. package/dist/cjs/airdrop/services/index.js +34 -5
  28. package/dist/cjs/airdrop/services/index.js.map +1 -1
  29. package/dist/cjs/airdrop/types/index.d.ts +51 -23
  30. package/dist/cjs/airdrop/types/index.js.map +1 -1
  31. package/dist/cjs/utils/api-client.d.ts +1 -0
  32. package/dist/cjs/utils/api-client.js +2 -2
  33. package/dist/cjs/utils/api-client.js.map +1 -1
  34. package/dist/esm/airdrop/AirdropClient.js +9 -2
  35. package/dist/esm/airdrop/AirdropClient.js.map +1 -1
  36. package/dist/esm/airdrop/SignatureAirdropClient.d.ts +22 -9
  37. package/dist/esm/airdrop/SignatureAirdropClient.js +96 -20
  38. package/dist/esm/airdrop/SignatureAirdropClient.js.map +1 -1
  39. package/dist/esm/airdrop/core/evm/SignatureAirdropService.d.ts +23 -0
  40. package/dist/esm/airdrop/core/evm/SignatureAirdropService.js +67 -0
  41. package/dist/esm/airdrop/core/evm/SignatureAirdropService.js.map +1 -0
  42. package/dist/esm/airdrop/core/evm/contracts/AirdropSignatureClient.d.ts +16 -0
  43. package/dist/esm/airdrop/core/evm/contracts/AirdropSignatureClient.js +40 -0
  44. package/dist/esm/airdrop/core/evm/contracts/AirdropSignatureClient.js.map +1 -0
  45. package/dist/esm/airdrop/core/evm/contracts/abis/FungibleTokenECDSADistributor.json +564 -0
  46. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.d.ts +1 -1
  47. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js +6 -3
  48. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.js.map +1 -1
  49. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/index.d.ts +2 -1
  50. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/index.js +7 -5
  51. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/evm/index.js.map +1 -1
  52. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/solana/index.d.ts +1 -1
  53. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js +11 -12
  54. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/solana/index.js.map +1 -1
  55. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.d.ts +1 -1
  56. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js +10 -9
  57. package/dist/esm/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.js.map +1 -1
  58. package/dist/esm/airdrop/services/index.d.ts +25 -8
  59. package/dist/esm/airdrop/services/index.js +31 -4
  60. package/dist/esm/airdrop/services/index.js.map +1 -1
  61. package/dist/esm/airdrop/types/index.d.ts +51 -23
  62. package/dist/esm/airdrop/types/index.js.map +1 -1
  63. package/dist/esm/utils/api-client.d.ts +1 -0
  64. package/dist/esm/utils/api-client.js +2 -2
  65. package/dist/esm/utils/api-client.js.map +1 -1
  66. package/package.json +3 -3
  67. package/src/airdrop/AirdropClient.ts +8 -2
  68. package/src/airdrop/SignatureAirdropClient.ts +155 -27
  69. package/src/airdrop/core/evm/SignatureAirdropService.ts +90 -0
  70. package/src/airdrop/core/evm/contracts/AirdropSignatureClient.ts +56 -0
  71. package/src/airdrop/core/evm/contracts/abis/FungibleTokenECDSADistributor.json +564 -0
  72. package/src/airdrop/core/useWeb3ConnectWallet/providers/evm/EvmWallet.ts +6 -3
  73. package/src/airdrop/core/useWeb3ConnectWallet/providers/evm/index.tsx +18 -5
  74. package/src/airdrop/core/useWeb3ConnectWallet/providers/solana/index.tsx +11 -14
  75. package/src/airdrop/core/useWeb3ConnectWallet/providers/ton/TonWallet.ts +16 -12
  76. package/src/airdrop/services/index.ts +75 -14
  77. package/src/airdrop/types/index.ts +55 -24
  78. package/src/utils/api-client.ts +3 -2
@@ -57,11 +57,11 @@ export class TonWallet extends WalletBase<TonStoreType> {
57
57
 
58
58
  async sign(originMsg: string): Promise<ISignResult> {
59
59
  const message = await hashSha256(originMsg);
60
- const tonConnectUI = tonStore.walletClient as TonConnectUI;
60
+ const tonConnectUI = tonStore.walletClient as any;
61
61
  // const walletInfo = tonConnectUI?.wallet;
62
62
  const authType = '';
63
63
  // if (walletInfo?.jsBridgeKey && walletInfo?.openMethod !== 'qrcode') {
64
- // authType = walletInfo.jsBridgeKey;
64
+ // authType = walletInfo.jsBridgeKey;
65
65
  // }
66
66
 
67
67
  console.log(this.isConnected, tonConnectUI, 'connected');
@@ -72,12 +72,10 @@ export class TonWallet extends WalletBase<TonStoreType> {
72
72
  if (authType) {
73
73
  const wallets = await tonConnectUI.getWallets();
74
74
 
75
- const currentWallet = wallets.find((wallet) =>
75
+ const currentWallet = wallets.find((wallet: any) =>
76
76
  [wallet.name, wallet.appName].includes(authType)
77
77
  ) as WalletInfoRemote;
78
78
 
79
- console.log(wallets, currentWallet, 'ww');
80
-
81
79
  const link = tonConnectUI.connector.connect(
82
80
  {
83
81
  bridgeUrl: currentWallet.bridgeUrl,
@@ -133,13 +131,19 @@ export class TonWallet extends WalletBase<TonStoreType> {
133
131
  };
134
132
  }
135
133
 
136
- override async signin(statement?: string): Promise<ISignResult> {
137
- const fullMessage = {
138
- statement: statement || 'Welcome to EthSign',
139
- issuedAt: new Date().toISOString(),
140
- nonce: getCustomNaNoId()
141
- };
142
- const signRes = await this.sign(JSON.stringify(fullMessage, null, ' '));
134
+ override async signin(statement: string, prepare = true): Promise<ISignResult> {
135
+ const fullMessage = prepare
136
+ ? JSON.stringify(
137
+ {
138
+ statement: statement || 'Welcome to EthSign',
139
+ issuedAt: new Date().toISOString(),
140
+ nonce: getCustomNaNoId()
141
+ },
142
+ null,
143
+ ' '
144
+ )
145
+ : statement;
146
+ const signRes = await this.sign(fullMessage);
143
147
  return signRes;
144
148
  }
145
149
 
@@ -1,6 +1,13 @@
1
1
  import { apiClient } from '../../utils/api-client';
2
2
  import { safeParseJSON } from '../../utils/utils';
3
- import { IAirdropData, IContractConfig, IProject } from '../types';
3
+ import {
4
+ AirdropSigIdentityTypeEnum,
5
+ IAirdropData,
6
+ IAirdropSignatureData,
7
+ IClaimSignature,
8
+ IContractConfig,
9
+ IProject
10
+ } from '../types';
4
11
 
5
12
  export { TonWalletService } from './wallet-service/ton';
6
13
 
@@ -11,7 +18,7 @@ const createApiClient = (baseURL?: string) => {
11
18
  export const getAirdropProject = async (projectId: string, baseURL?: string): Promise<IProject> => {
12
19
  const client = createApiClient(baseURL);
13
20
  const res = await client.get<any>(`/airdrop-open/projects/${projectId}`);
14
- if (!res) return res; // res为null
21
+ if (!res) return res; // res is null
15
22
  const projectConfig = res?.themeConf;
16
23
  const blockCountries = safeParseJSON(projectConfig?.blockCountries);
17
24
  return {
@@ -70,27 +77,81 @@ export const getJettonInfo = async (
70
77
  return client.get(`/airdrop-open/jetton/${data.address}?isTestnet=${data.isTestnet}`);
71
78
  };
72
79
 
73
- export const connectTwitter = async (data: { code: string; redirectUri: string }, baseURL?: string) => {
80
+ interface SidResponse {
81
+ sid: string;
82
+ }
83
+
84
+ interface TwitterConnectParams {
85
+ code: string;
86
+ projectId: string;
87
+ }
88
+
89
+ interface WalletBindParams {
90
+ projectId: string;
91
+ key: string;
92
+ signature: string;
93
+ message: string;
94
+ timestamp: number;
95
+ recipientType: string;
96
+ }
97
+
98
+ const getSidHeader = (projectId: string) => ({
99
+ sid: window.localStorage.getItem(`sid_${projectId}`) || ''
100
+ });
101
+
102
+ export const connectTwitter = async (data: TwitterConnectParams, baseURL?: string): Promise<SidResponse> => {
103
+ const client = createApiClient(baseURL);
104
+ return client.post('/airdrop-open/connect-twitter', data, {
105
+ headers: getSidHeader(data.projectId)
106
+ });
107
+ };
108
+
109
+ export const checkEligibility = async (
110
+ data: { projectId: string },
111
+ baseURL?: string
112
+ ): Promise<IAirdropSignatureData> => {
113
+ const headers = getSidHeader(data.projectId);
114
+ if (!headers.sid)
115
+ return {
116
+ claims: [],
117
+ identities: []
118
+ };
74
119
  const client = createApiClient(baseURL);
75
- return client.post('/airdrop-open/connect-twitter', data);
120
+
121
+ return client.post('/airdrop-open/check-eligibility', data, {
122
+ headers: headers
123
+ });
76
124
  };
77
125
 
78
- export const checkEligibility = async (data: { projectId: string }, baseURL?: string) => {
126
+ export const bindWallet = async (data: WalletBindParams, baseURL?: string): Promise<SidResponse> => {
79
127
  const client = createApiClient(baseURL);
80
- return client.post('/airdrop-open/check-eligibility', data);
128
+ return client.post('/airdrop-open/connect-wallet', data, {
129
+ headers: getSidHeader(data.projectId)
130
+ });
81
131
  };
82
132
 
83
- export const bindWallet = async (
133
+ interface DisconnectParams {
134
+ projectId: string;
135
+ recipientType: AirdropSigIdentityTypeEnum;
136
+ recipient?: string;
137
+ }
138
+
139
+ export const disconnectRecipient = async (data: DisconnectParams, baseURL?: string): Promise<void> => {
140
+ const client = createApiClient(baseURL);
141
+ return client.post('/airdrop-open/disconnect', data, {
142
+ headers: getSidHeader(data.projectId)
143
+ });
144
+ };
145
+
146
+ export const checkGetSignatures = async (
84
147
  data: {
85
148
  projectId: string;
86
- key: string;
87
- signature: string;
88
- message: string;
89
- timestamp: number;
90
- recipientType: string;
149
+ claimIds: string[];
91
150
  },
92
151
  baseURL?: string
93
- ) => {
152
+ ): Promise<{ signatures: IClaimSignature[] }> => {
94
153
  const client = createApiClient(baseURL);
95
- return client.post('/airdrop-open/connect-wallet', data);
154
+ return client.post('/airdrop-open/check-get-signatures', data, {
155
+ headers: getSidHeader(data.projectId)
156
+ });
96
157
  };
@@ -1,7 +1,6 @@
1
1
  import { TonConnectUI } from '@tonconnect/ui-react';
2
2
  import { AirdropService as TonAirdropService } from '../core/ton/AirdropService';
3
3
  import { AirdropService as EvmAirdropService } from '../core/evm/AirdropService';
4
- import { TonClient } from '@ton/ton';
5
4
  import { ChainConfig } from '../constants';
6
5
  import { WalletClient as ViemWalletClient } from 'viem';
7
6
 
@@ -20,29 +19,29 @@ export enum ChainType {
20
19
  }
21
20
 
22
21
  export type ThemeConfig = {
23
- logo: string;
24
- title: string;
25
- description: string;
26
- coverImage: string;
27
- subTitle: string;
28
- primaryColor: string;
29
- secondaryColor: string;
30
- buttonPrimaryHover: string;
31
- buttonSecondaryHover: string;
32
- buttonPrimaryForeground: string;
33
- buttonSecondaryForeground: string;
34
- welcomeModalText: string;
35
- welcomeModalTitle: string;
36
- isShowWelcomeModal: boolean;
37
- blockCountries: string;
38
- termsOfUse: string;
39
- successModalPrimaryBtnText: string;
40
- successModalUrl: string;
41
- successModalTitle: string;
42
- successModalDesc: string;
43
- successModalShareTexts: string;
44
- isUnAvailable: boolean;
45
- privacyPolicy: string;
22
+ logo?: string;
23
+ title?: string;
24
+ description?: string;
25
+ coverImage?: string;
26
+ subTitle?: string;
27
+ primaryColor?: string;
28
+ secondaryColor?: string;
29
+ buttonPrimaryHover?: string;
30
+ buttonSecondaryHover?: string;
31
+ buttonPrimaryForeground?: string;
32
+ buttonSecondaryForeground?: string;
33
+ welcomeModalText?: string;
34
+ welcomeModalTitle?: string;
35
+ isShowWelcomeModal?: boolean;
36
+ blockCountries?: string;
37
+ termsOfUse?: string;
38
+ successModalPrimaryBtnText?: string;
39
+ successModalUrl?: string;
40
+ successModalTitle?: string;
41
+ successModalDesc?: string;
42
+ successModalShareTexts?: string;
43
+ isUnAvailable?: boolean;
44
+ privacyPolicy?: string;
46
45
  };
47
46
 
48
47
  export interface IProject {
@@ -63,6 +62,7 @@ export interface IProject {
63
62
  version: string;
64
63
  extra?: IProjectExtra;
65
64
  identities: Identity[];
65
+ projectTag: string;
66
66
  }
67
67
 
68
68
  export interface Identity {
@@ -113,10 +113,40 @@ export type IAirdropClaim = {
113
113
  project: IProject;
114
114
  };
115
115
 
116
+ export type IAirdropSignatureClaim = {
117
+ percent: number;
118
+ unlockingAt: number;
119
+ claimDeadline: number;
120
+ value: string;
121
+ recipient: string;
122
+ recipientType: string;
123
+ claimId: string;
124
+ data?: string;
125
+ signature?: string;
126
+ claimed?: boolean;
127
+ };
128
+
129
+ export interface IAirdropSignatureIdentity {
130
+ type: AirdropSigIdentityTypeEnum;
131
+ value: string;
132
+ displayName: string;
133
+ }
134
+
116
135
  export interface IAirdropData {
117
136
  claims: IAirdropClaim[];
118
137
  }
119
138
 
139
+ export interface IAirdropSignatureData {
140
+ claims: IAirdropSignatureClaim[];
141
+ identities: IAirdropSignatureIdentity[];
142
+ }
143
+
144
+ export interface IClaimSignature {
145
+ claimId: string;
146
+ data: string;
147
+ signature: string;
148
+ }
149
+
120
150
  export enum TonAirdropVersionEnum {
121
151
  V1 = '1.0.0',
122
152
  V2 = '2.0.0',
@@ -136,6 +166,7 @@ export type IAirdropService = TonAirdropService | EvmAirdropService;
136
166
 
137
167
  type BaseAirdropOptions = {
138
168
  endpoint?: string;
169
+ project?: IProject;
139
170
  };
140
171
 
141
172
  type ProjectIdOptions = BaseAirdropOptions & {
@@ -5,6 +5,7 @@ export type ApiClientOptions = {
5
5
  export type ApiRequestOptions = {
6
6
  params?: Record<string, string | number>;
7
7
  skipHandleError?: boolean;
8
+ headers?: Record<string, string>;
8
9
  };
9
10
 
10
11
  type ApiResponse = {
@@ -48,11 +49,11 @@ export class ApiClient {
48
49
  ): Promise<unknown> {
49
50
  const finalUrl = (this.options?.baseURL || '') + url;
50
51
 
51
- const init: RequestInit = { method };
52
+ const init: RequestInit = { method, headers: options?.headers || {} };
52
53
  if (data instanceof FormData) {
53
54
  init.body = data;
54
55
  } else {
55
- init.headers = { 'content-type': 'application/json' };
56
+ init.headers = { 'content-type': 'application/json', ...init.headers };
56
57
  init.body = data ? JSON.stringify(data) : void 0;
57
58
  }
58
59