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

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 +27 -0
  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 +27 -0
  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 +31 -1
  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
 
@@ -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,39 @@ 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
+ }
133
+
116
134
  export interface IAirdropData {
117
135
  claims: IAirdropClaim[];
118
136
  }
119
137
 
138
+ export interface IAirdropSignatureData {
139
+ claims: IAirdropSignatureClaim[];
140
+ identities: IAirdropSignatureIdentity[];
141
+ }
142
+
143
+ export interface IClaimSignature {
144
+ claimId: string;
145
+ data: string;
146
+ signature: string;
147
+ }
148
+
120
149
  export enum TonAirdropVersionEnum {
121
150
  V1 = '1.0.0',
122
151
  V2 = '2.0.0',
@@ -136,6 +165,7 @@ export type IAirdropService = TonAirdropService | EvmAirdropService;
136
165
 
137
166
  type BaseAirdropOptions = {
138
167
  endpoint?: string;
168
+ project?: IProject;
139
169
  };
140
170
 
141
171
  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