@zeni-wallet/connect-protocol 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zeni Wallet Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,13 @@
1
- # Temporary Holding Version
1
+ # @zeni-wallet/connect-protocol
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Wire types and WebCrypto AES-256-GCM primitives shared by the Zeni Connect SDK. Most web apps should use `@zeni-wallet/connect` or `@zeni-wallet/react`.
4
+
5
+ ## Installation
6
+
7
+ The first npm release is being prepared; these packages are not published yet. Use the local tarballs described in the [SDK guide](https://github.com/Trymbakmahant/zeni-wallet/blob/main/docs/ZENI_CONNECT.md) until publication is confirmed. Release maintainers should follow the [npm release guide](https://github.com/Trymbakmahant/zeni-wallet/blob/main/docs/NPM_RELEASE.md).
8
+
9
+ This package is ESM and includes TypeScript declarations. Browser integrations require a secure context with WebCrypto and modern fetch/AbortSignal support.
10
+
11
+ Frames bind protocol version, session ID, sender role, and frame ID as authenticated additional data. Ciphertext contains the 16-byte authentication tag appended to the encrypted JSON, matching CryptoKit on iOS. Each frame has a fresh 12-byte nonce. Keys are generated from 32 random bytes and transferred only in a `zeni://connect#...` QR/deep-link fragment.
12
+
13
+ See `docs/ZENI_CONNECT.md` in the repository for the full protocol and deployment limits.
@@ -0,0 +1,63 @@
1
+ export declare const CHAIN_ID = "0x2648";
2
+ export declare const METHODS: readonly ["zeni_sendQor", "personal_sign"];
3
+ export declare const MAX_FRAME_BYTES = 32768;
4
+ export type Role = 'dapp' | 'wallet';
5
+ export type RpcRequest = {
6
+ id: string;
7
+ method: string;
8
+ params?: unknown[];
9
+ };
10
+ export type RpcError = {
11
+ code: number;
12
+ message: string;
13
+ };
14
+ export type Message = {
15
+ type: 'approved';
16
+ account: string;
17
+ chainId: string;
18
+ expiresAt: number;
19
+ } | {
20
+ type: 'rejected';
21
+ reason: string;
22
+ } | {
23
+ type: 'request';
24
+ request: RpcRequest;
25
+ expiresAt: number;
26
+ } | {
27
+ type: 'response';
28
+ id: string;
29
+ result?: unknown;
30
+ error?: RpcError;
31
+ } | {
32
+ type: 'disconnect';
33
+ };
34
+ export interface Envelope {
35
+ id: string;
36
+ iv: string;
37
+ ciphertext: string;
38
+ }
39
+ export interface Pairing {
40
+ relay: string;
41
+ session: string;
42
+ token: string;
43
+ key: string;
44
+ }
45
+ export interface SessionInfo {
46
+ id: string;
47
+ origin: string;
48
+ name: string;
49
+ expiresAt: number;
50
+ active: boolean;
51
+ }
52
+ export declare class ZeniError extends Error {
53
+ code: number;
54
+ constructor(code: number, message: string);
55
+ }
56
+ export declare function base64url(bytes: Uint8Array): string;
57
+ export declare function unbase64url(value: string): Uint8Array;
58
+ export declare function secret(): string;
59
+ export declare function relayURL(value: string): string;
60
+ export declare function pairingURI(pairing: Pairing): string;
61
+ export declare function parsePairing(uri: string): Pairing;
62
+ export declare function seal(key: string, session: string, role: Role, message: Message): Promise<Envelope>;
63
+ export declare function open(key: string, session: string, role: Role, frame: Envelope): Promise<Message>;
package/dist/index.js ADDED
@@ -0,0 +1,63 @@
1
+ export const CHAIN_ID = '0x2648';
2
+ export const METHODS = ['zeni_sendQor', 'personal_sign'];
3
+ export const MAX_FRAME_BYTES = 32768;
4
+ export class ZeniError extends Error {
5
+ code;
6
+ constructor(code, message) {
7
+ super(message);
8
+ this.code = code;
9
+ this.name = 'ZeniError';
10
+ }
11
+ }
12
+ export function base64url(bytes) {
13
+ return btoa(String.fromCharCode(...bytes)).replaceAll('+', '-').replaceAll('/', '_').replace(/=+$/, '');
14
+ }
15
+ export function unbase64url(value) {
16
+ if (!/^[A-Za-z0-9_-]+$/.test(value))
17
+ throw new Error('Invalid base64url');
18
+ return Uint8Array.from(atob(value.replaceAll('-', '+').replaceAll('_', '/')), c => c.charCodeAt(0));
19
+ }
20
+ export function secret() { return base64url(crypto.getRandomValues(new Uint8Array(32))); }
21
+ export function relayURL(value) {
22
+ const url = new URL(value);
23
+ const local = ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
24
+ if ((url.protocol !== 'https:' && !(url.protocol === 'http:' && local)) || url.username || url.password || url.search || url.hash || url.pathname !== '/') {
25
+ throw new Error('Relay must be an HTTPS origin (HTTP is allowed only on localhost).');
26
+ }
27
+ return url.origin;
28
+ }
29
+ export function pairingURI(pairing) {
30
+ return 'zeni://connect#' + new URLSearchParams({ v: '1', ...pairing });
31
+ }
32
+ export function parsePairing(uri) {
33
+ if (uri.length > 2048)
34
+ throw new Error('Invalid pairing URI');
35
+ const url = new URL(uri), params = new URLSearchParams(url.hash.slice(1));
36
+ if (url.protocol !== 'zeni:' || url.host !== 'connect' || url.search || params.get('v') !== '1')
37
+ throw new Error('Unsupported pairing URI');
38
+ const session = params.get('session') || '', token = params.get('token') || '', key = params.get('key') || '';
39
+ if (!/^[a-f0-9]{32}$/.test(session) || !/^[A-Za-z0-9_-]{43}$/.test(token) || !/^[A-Za-z0-9_-]{43}$/.test(key))
40
+ throw new Error('Invalid pairing credentials');
41
+ return { relay: relayURL(params.get('relay') || ''), session, token, key };
42
+ }
43
+ const aad = (session, role, id) => new TextEncoder().encode(`zeni-connect:v1:${session}:${role}:${id}`);
44
+ export async function seal(key, session, role, message) {
45
+ const plaintext = new TextEncoder().encode(JSON.stringify(message));
46
+ if (plaintext.length > 20000)
47
+ throw new Error('Message too large');
48
+ const id = crypto.randomUUID(), iv = crypto.getRandomValues(new Uint8Array(12));
49
+ const aes = await crypto.subtle.importKey('raw', unbase64url(key), 'AES-GCM', false, ['encrypt']);
50
+ const ciphertext = await crypto.subtle.encrypt({ name: 'AES-GCM', iv, additionalData: aad(session, role, id) }, aes, plaintext);
51
+ return { id, iv: base64url(iv), ciphertext: base64url(new Uint8Array(ciphertext)) };
52
+ }
53
+ export async function open(key, session, role, frame) {
54
+ if (!frame || typeof frame.id !== 'string' || typeof frame.iv !== 'string' || typeof frame.ciphertext !== 'string'
55
+ || frame.ciphertext.length > MAX_FRAME_BYTES || unbase64url(frame.iv).length !== 12)
56
+ throw new Error('Invalid encrypted frame');
57
+ const aes = await crypto.subtle.importKey('raw', unbase64url(key), 'AES-GCM', false, ['decrypt']);
58
+ const plaintext = await crypto.subtle.decrypt({ name: 'AES-GCM', iv: unbase64url(frame.iv), additionalData: aad(session, role, frame.id) }, aes, unbase64url(frame.ciphertext));
59
+ const message = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(plaintext));
60
+ if (!message || !['approved', 'rejected', 'request', 'response', 'disconnect'].includes(message.type))
61
+ throw new Error('Invalid protocol message');
62
+ return message;
63
+ }
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@zeni-wallet/connect-protocol",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "files": [
7
+ "dist",
8
+ "README.md",
9
+ "LICENSE"
10
+ ],
11
+ "main": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ }
18
+ },
19
+ "devDependencies": {
20
+ "typescript": "^5.4.5"
21
+ },
22
+ "description": "Wire types and encrypted transport primitives for Zeni Connect",
23
+ "homepage": "https://zeni-wallet.vercel.app/docs",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/Trymbakmahant/zeni-wallet.git",
27
+ "directory": "packages/connect-protocol"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/Trymbakmahant/zeni-wallet/issues"
31
+ },
32
+ "keywords": [
33
+ "zeni",
34
+ "wallet",
35
+ "qorechain",
36
+ "sdk"
37
+ ],
38
+ "publishConfig": {
39
+ "access": "public",
40
+ "registry": "https://registry.npmjs.org/"
41
+ },
42
+ "scripts": {
43
+ "build": "tsc"
44
+ }
6
45
  }