zigap-utils 3.1.0-preview.1 → 3.1.0-preview.4
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/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/useAddressProvideReceive.d.ts +17 -0
- package/dist/hooks/useDeeplinkAppSwitch.d.ts +10 -0
- package/dist/hooks/useDeeplinkLogin.d.ts +22 -0
- package/dist/hooks/useDeeplinkPayment.d.ts +23 -0
- package/dist/hooks/useDeeplinkResume.d.ts +27 -0
- package/dist/hooks/useDeeplinkRoom.d.ts +18 -0
- package/dist/hooks/useDeeplinkSendTransaction.d.ts +21 -0
- package/dist/hooks/useDeeplinkSignature.d.ts +22 -0
- package/dist/hooks/useRoomExpiry.d.ts +2 -0
- package/dist/hooks/useSocketRoom.d.ts +7 -0
- package/dist/hooks/useZigap.d.ts +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.es.js +9498 -9293
- package/dist/utils/deeplinkTransport.d.ts +68 -0
- package/dist/utils/device.d.ts +14 -0
- package/dist/utils/handshake.d.ts +6 -0
- package/dist/utils/resumeLoginResult.d.ts +25 -0
- package/dist/utils/socketService.d.ts +5 -0
- package/dist/zigap/qr.d.ts +0 -1
- package/dist/zigap/scanUrl.d.ts +9 -0
- package/package.json +64 -69
- package/dist/utils/session.d.ts +0 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* deeplinkTransport — type-무관 store-and-forward transport (서버 StoreForwardStore 의 클라이언트 짝).
|
|
3
|
+
*
|
|
4
|
+
* 딥링크로 dapp 탭이 꺼졌다 살아나도 연결을 끝까지 잇기 위한 모듈.
|
|
5
|
+
* envelope({roomId,type,payload,nonce,ttl})를 해석하지 않고 그대로 실어 보낸다 —
|
|
6
|
+
* type-무관 transport, login 외 type 은 envelope.type 만 바꿔 재사용(보고서 §7.1).
|
|
7
|
+
* login 은 첫 consumer 일 뿐, sendTransaction/payment 도 같은 모듈을 공유한다.
|
|
8
|
+
*
|
|
9
|
+
* 저장소 백엔드(LOCKED 가드): 스냅샷은 원시 localStorage 직접 호출(setItem/getItem/removeItem)만 쓴다 —
|
|
10
|
+
* 기존 zigap-utils 패턴(useZigap.ts 의 LOGIN_RES_KEY)과 동일.
|
|
11
|
+
* - ❌ ZIGAP.Store(zigap.io 전용; app=secureStorage 분기)를 끌어오지 않는다 — dapp 은 항상 browser 컨텍스트.
|
|
12
|
+
* - ❌ sessionStorage 도 쓰지 않는다 — 탭 discard 시 소멸해 unload 2겹 보존이 무력화된다.
|
|
13
|
+
*
|
|
14
|
+
* localStorage 경계(LOCKED 가드): 스냅샷은 dapp 자기 상태(roomId/nonce/pending) 보존 전용이다.
|
|
15
|
+
* 앱→dapp 결과 전달(cross-process)에는 절대 쓰지 않는다 — 결과는 서버 보관/소켓(resumeRoom)으로만(보고서 §3).
|
|
16
|
+
*/
|
|
17
|
+
export type DeeplinkEnvelopeType = 'login' | 'signMessage' | 'sendTransaction' | 'payment';
|
|
18
|
+
export interface DeeplinkEnvelope {
|
|
19
|
+
roomId: string;
|
|
20
|
+
type: DeeplinkEnvelopeType | string;
|
|
21
|
+
payload: any;
|
|
22
|
+
nonce: string;
|
|
23
|
+
ttl?: number;
|
|
24
|
+
}
|
|
25
|
+
export type SnapshotStatus = 'pending' | 'done';
|
|
26
|
+
export interface DeeplinkSnapshot {
|
|
27
|
+
roomId: string;
|
|
28
|
+
type: DeeplinkEnvelopeType | string;
|
|
29
|
+
status: SnapshotStatus;
|
|
30
|
+
nonce: string;
|
|
31
|
+
startedAt: number;
|
|
32
|
+
}
|
|
33
|
+
export type ResumeAction = 'resume' | 'noop' | 'timeout';
|
|
34
|
+
/**
|
|
35
|
+
* 복귀했을 때 무엇을 할지 결정하는 순수 함수 (DOM·소켓에 의존 안 해 단위 검증 가능).
|
|
36
|
+
* type 비의존 — 어떤 type 의 스냅샷이든 동일하게 동작한다(type-무관).
|
|
37
|
+
*
|
|
38
|
+
* 스냅샷 없음 / 이미 완료('done') → noop (할 일 없음; null→noop 로 데스크톱 격리 DeepLink-01)
|
|
39
|
+
* 화면이 아직 안 보임(백그라운드) → noop (보일 때까지 대기)
|
|
40
|
+
* 시작 후 timeoutMs 초과 → timeout (시간 초과 안내)
|
|
41
|
+
* 그 외(진행중 + 화면 보임 + 시간 내) → resume (이어서 진행)
|
|
42
|
+
*/
|
|
43
|
+
export declare const computeResumeAction: (snapshot: DeeplinkSnapshot | null | undefined, visibilityState: string, now?: number, timeoutMs?: number) => ResumeAction;
|
|
44
|
+
/** 진행중('pending') 상태의 스냅샷 객체를 만든다 (순수). type='login'/'signMessage' 동일 구조(type-무관). */
|
|
45
|
+
export declare const makeSnapshot: (roomId: string, nonce: string, type: DeeplinkEnvelopeType | string) => DeeplinkSnapshot;
|
|
46
|
+
/**
|
|
47
|
+
* envelope 를 해석하지 않고 그대로 서버에 실어 보내는 type-무관 transport 클래스.
|
|
48
|
+
* register/resume 는 socketService emit, snapshot* 은 원시 localStorage I/O 뿐이다.
|
|
49
|
+
*/
|
|
50
|
+
declare class DeeplinkTransportService {
|
|
51
|
+
/** 딥링크로 넘어가기 직전, 서명할 메시지(envelope)를 서버에 미리 맡겨둔다 (선등록 DeepLink-02). */
|
|
52
|
+
register(roomId: string, envelope: DeeplinkEnvelope): void;
|
|
53
|
+
/** 돌아왔을 때 방에 다시 들어가 서버 보관분을 받아온다 (resumeRoom pull). */
|
|
54
|
+
resume(roomId: string): void;
|
|
55
|
+
/** 스냅샷을 원시 localStorage 에 저장한다 (dapp 자기 상태 보존 전용 — 결과 전달엔 절대 미사용). */
|
|
56
|
+
snapshotSave(snapshot: DeeplinkSnapshot): void;
|
|
57
|
+
snapshotLoad(roomId: string): DeeplinkSnapshot | null;
|
|
58
|
+
snapshotClear(roomId: string): void;
|
|
59
|
+
snapshotClearAll(): void;
|
|
60
|
+
/**
|
|
61
|
+
* 보관된 pending 스냅샷 중 미만료 최신 1건을 반환한다 (풀 리로드 복귀 시 원래 방 복구용).
|
|
62
|
+
* 스냅샷엔 ttl 필드가 없어 기본 timeout 창(DEFAULT_TIMEOUT_MS)을 만료 기준으로 쓴다.
|
|
63
|
+
* 만료 항목은 순회하며 removeItem 으로 정리한다. done/파싱불가/없음 → null.
|
|
64
|
+
*/
|
|
65
|
+
snapshotLoadAnyPending(now?: number, timeoutMs?: number): DeeplinkSnapshot | null;
|
|
66
|
+
}
|
|
67
|
+
export declare const deeplinkTransport: DeeplinkTransportService;
|
|
68
|
+
export default deeplinkTransport;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UA·포인터 입력만으로 모바일 여부를 판별하는 순수 함수.
|
|
3
|
+
* DOM 없이 단위 검증 가능하도록 분리한다 (device.test.mjs 가 동일 로직을 어서션).
|
|
4
|
+
*/
|
|
5
|
+
export declare const detectIsMobileFromInputs: (userAgent: string, isCoarsePointer: boolean) => boolean;
|
|
6
|
+
declare class DeviceService {
|
|
7
|
+
/**
|
|
8
|
+
* 표준 웹 API(navigator.userAgent + matchMedia('(pointer: coarse)'))만으로 모바일을 판별한다.
|
|
9
|
+
* SSR(window/navigator 부재)에서는 절대 throw 하지 않고 false 를 반환한다.
|
|
10
|
+
*/
|
|
11
|
+
isMobile(): boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const device: DeviceService;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function receiveRequest(roomId: string): Promise<{
|
|
2
|
+
roomId: string;
|
|
3
|
+
isSuccess: boolean;
|
|
4
|
+
}>;
|
|
5
|
+
export declare function sendMessage(roomId: string, message: string): Promise<void>;
|
|
6
|
+
export declare function checkVerified(roomId: string, verified: boolean): Promise<string>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** 모바일 resume(서버 보관분) 결과에 공통으로 비어 오는 인증 필드 — Login/Sig 가 같은 모양을 쓴다. */
|
|
2
|
+
interface ResumeLoginFields {
|
|
3
|
+
token?: string;
|
|
4
|
+
signature?: string;
|
|
5
|
+
issuedDateTime?: string;
|
|
6
|
+
expire?: {
|
|
7
|
+
type: 'NONE';
|
|
8
|
+
} | {
|
|
9
|
+
type: 'FIX' | 'EXTEND';
|
|
10
|
+
seconds: number;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
type ExpireOption = {
|
|
14
|
+
type: 'NONE' | 'FIX' | 'EXTEND';
|
|
15
|
+
seconds?: number;
|
|
16
|
+
} | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* resume 결과는 token/issuedDateTime/expire 가 비어 온다(signature·address 등은 옴).
|
|
19
|
+
* LoginQR/SignatureQR 은 EVM 네트워크 전용이라 token payload 에 publicKey 가 없다 —
|
|
20
|
+
* signature(resume 보유) + message 만으로 라이브와 동일한 token 을 조립한다.
|
|
21
|
+
* token 이 라이브와 바이트 단위로 같아야 하므로 message 는 sigMessage·nonce 로 여기서 만든다.
|
|
22
|
+
* result 를 제자리에서 보강한다.
|
|
23
|
+
*/
|
|
24
|
+
export declare const completeResumeLoginResult: (result: ResumeLoginFields, sigMessage: string, nonce: string, expire: ExpireOption) => void;
|
|
25
|
+
export default completeResumeLoginResult;
|
|
@@ -12,6 +12,11 @@ declare class SocketService {
|
|
|
12
12
|
onAirdropResult(callback: (message: any) => void): void;
|
|
13
13
|
offAirdropResult(): void;
|
|
14
14
|
confirmSendTransaction(roomId: string, message: string): Socket;
|
|
15
|
+
registerMessage(roomId: string, envelope: unknown): Socket;
|
|
16
|
+
resumeRoom(roomId: string): Socket;
|
|
17
|
+
isConnected(): boolean;
|
|
18
|
+
onceConnect(callback: () => void): void;
|
|
19
|
+
offConnect(callback: () => void): void;
|
|
15
20
|
onMessageReceived(type: string, callback: (message: any) => void): void;
|
|
16
21
|
offMessageReceived(type: string): void;
|
|
17
22
|
}
|
package/dist/zigap/qr.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ declare class QrService {
|
|
|
6
6
|
generatePaymentQrCode(dapp: string, network: string, address: string, amount: string, description: string | undefined, info: string | undefined, qrDomain?: string): QrType;
|
|
7
7
|
generateAirdropQrCode(dapp: string, network: string[], icon: string | undefined, qrDomain?: string): QrType;
|
|
8
8
|
generateSendTransactionQrCode(dapp: string, networks: 'binance' | 'ethereum' | 'v2xphere' | 'v3xphere', url: string, icon: string | undefined, qrDomain?: string): QrType;
|
|
9
|
-
private getQrDomain;
|
|
10
9
|
}
|
|
11
10
|
export declare const Qr: QrService;
|
|
12
11
|
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 공용 scan-URL 빌더 — qr.ts 의 5개 generator 가 반복하던 URL 인코딩 패턴
|
|
3
|
+
* (URLSearchParams → 퍼센트 인코딩 → 도메인 결합)을 한 곳에 모은다.
|
|
4
|
+
*
|
|
5
|
+
* import 가 전혀 없는 순수 모듈이어야 한다. tests/qrScanUrl.test.mjs 가
|
|
6
|
+
* 이 파일을 relative 경로로 의존성 없이 import 해 바이트 동일성을 검증한다.
|
|
7
|
+
*/
|
|
8
|
+
export type ScanType = 'login' | 'provide' | 'payment' | 'airdrop' | 'sendTransaction';
|
|
9
|
+
export declare function buildScanUrl(type: ScanType, params: Record<string, string>, qrDomain?: string): string;
|
package/package.json
CHANGED
|
@@ -1,70 +1,65 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"vite-plugin-css-injected-by-js": "^3.5.1",
|
|
67
|
-
"vite-plugin-dts": "^3.9.1",
|
|
68
|
-
"vite-tsconfig-paths": "^4.3.2"
|
|
69
|
-
}
|
|
70
|
-
}
|
|
2
|
+
"name": "zigap-utils",
|
|
3
|
+
"version": "3.1.0-preview.4",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.es.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"author": "Seoullabs",
|
|
8
|
+
"license": "ISC",
|
|
9
|
+
"homepage": "https://seoul-labs.gitbook.io/zigap-utils",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/Seoullabs-official/zigap-utils"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
19
|
+
"dayjs": "^1.11.11",
|
|
20
|
+
"dotenv": "^16.4.5",
|
|
21
|
+
"react": "^18.2.0 || ^19.0.0",
|
|
22
|
+
"react-dom": "^18.2.0 || ^19.0.0",
|
|
23
|
+
"styled-components": "^6.1.11",
|
|
24
|
+
"tsx": "^4.16.2",
|
|
25
|
+
"tweetnacl": "^1.0.3",
|
|
26
|
+
"vite-plugin-commonjs": "^0.10.1",
|
|
27
|
+
"web3": "^4.16.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/crypto-js": "^4.2.2",
|
|
31
|
+
"@types/elliptic": "^6.4.18",
|
|
32
|
+
"@types/node": "^20.12.12",
|
|
33
|
+
"@types/react": "^19.0.0",
|
|
34
|
+
"@types/react-dom": "^19.0.0",
|
|
35
|
+
"@types/styled-components": "^5.1.34",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
|
37
|
+
"@typescript-eslint/parser": "^7.2.0",
|
|
38
|
+
"@vitejs/plugin-react": "^4.2.1",
|
|
39
|
+
"crypto-js": "^4.2.0",
|
|
40
|
+
"elliptic": "^6.5.5",
|
|
41
|
+
"eslint": "^8.57.0",
|
|
42
|
+
"eslint-config-prettier": "^9.1.0",
|
|
43
|
+
"eslint-plugin-import": "^2.29.1",
|
|
44
|
+
"eslint-plugin-jsx-a11y": "^6.8.0",
|
|
45
|
+
"eslint-plugin-react": "^7.34.1",
|
|
46
|
+
"eslint-plugin-react-hooks": "^4.6.2",
|
|
47
|
+
"eslint-plugin-react-refresh": "^0.4.6",
|
|
48
|
+
"path": "^0.12.7",
|
|
49
|
+
"prettier": "^3.2.5",
|
|
50
|
+
"qrcode.react": "^4.2.0",
|
|
51
|
+
"socket.io-client": "^4.7.5",
|
|
52
|
+
"typescript": "^5.2.2",
|
|
53
|
+
"vite": "^5.2.0",
|
|
54
|
+
"vite-plugin-css-injected-by-js": "^3.5.1",
|
|
55
|
+
"vite-plugin-dts": "^3.9.1",
|
|
56
|
+
"vite-tsconfig-paths": "^4.3.2"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"preinstall": "npx only-allow pnpm",
|
|
60
|
+
"dev": "vite",
|
|
61
|
+
"build": "rm -rf dist && tsx ./src/preprocessEnv.ts && vite build",
|
|
62
|
+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
63
|
+
"preview": "vite preview"
|
|
64
|
+
}
|
|
65
|
+
}
|
package/dist/utils/session.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const clearSession: () => void;
|