@genation/bridge-peer 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/GenationBridgePeer.podspec +17 -0
- package/LICENSE +190 -0
- package/README.md +66 -0
- package/package.json +59 -0
- package/react-native/android/build.gradle +24 -0
- package/react-native/android/src/main/java/com/genation/bridge/GenationBridgePeerModule.kt +182 -0
- package/react-native/android/src/main/java/com/genation/bridge/GenationBridgePeerPackage.kt +15 -0
- package/react-native/android/src/main/jniLibs/arm64-v8a/libgenation_bridge_crypto_uniffi.so +0 -0
- package/react-native/android/src/main/jniLibs/armeabi-v7a/libgenation_bridge_crypto_uniffi.so +0 -0
- package/react-native/android/src/main/jniLibs/x86/libgenation_bridge_crypto_uniffi.so +0 -0
- package/react-native/android/src/main/jniLibs/x86_64/libgenation_bridge_crypto_uniffi.so +0 -0
- package/react-native/generated/kotlin/uniffi/genation_bridge_crypto_uniffi/genation_bridge_crypto_uniffi.kt +2006 -0
- package/react-native/generated/swift/GenationBridgeCryptoMobile.swift +1072 -0
- package/react-native/generated/swift/GenationBridgeCryptoMobileFFI.h +703 -0
- package/react-native/generated/swift/GenationBridgeCryptoMobileFFI.modulemap +7 -0
- package/react-native/ios/GenationBridgePeer.m +14 -0
- package/react-native/ios/GenationBridgePeer.swift +234 -0
- package/react-native/native/GenationBridgeCryptoMobile.xcframework/Info.plist +48 -0
- package/react-native/native/GenationBridgeCryptoMobile.xcframework/ios-arm64/Headers/GenationBridgeCryptoMobileFFI.h +703 -0
- package/react-native/native/GenationBridgeCryptoMobile.xcframework/ios-arm64/Headers/module.modulemap +7 -0
- package/react-native/native/GenationBridgeCryptoMobile.xcframework/ios-arm64/libgenation_bridge_crypto_uniffi.a +0 -0
- package/react-native/native/GenationBridgeCryptoMobile.xcframework/ios-arm64_x86_64-simulator/Headers/GenationBridgeCryptoMobileFFI.h +703 -0
- package/react-native/native/GenationBridgeCryptoMobile.xcframework/ios-arm64_x86_64-simulator/Headers/module.modulemap +7 -0
- package/react-native/native/GenationBridgeCryptoMobile.xcframework/ios-arm64_x86_64-simulator/libgenation_bridge_crypto_uniffi.a +0 -0
- package/react-native.config.js +8 -0
- package/src/core/codec.d.ts +5 -0
- package/src/core/codec.js +46 -0
- package/src/core/errors.d.ts +11 -0
- package/src/core/errors.js +27 -0
- package/src/core/identity.d.ts +16 -0
- package/src/core/identity.js +1 -0
- package/src/core/lifecycle.d.ts +4 -0
- package/src/core/lifecycle.js +1 -0
- package/src/core/mod.d.ts +6 -0
- package/src/core/mod.js +3 -0
- package/src/core/peer.d.ts +67 -0
- package/src/core/peer.js +373 -0
- package/src/core/runtime.d.ts +78 -0
- package/src/core/runtime.js +0 -0
- package/src/node/crypto-core/javascript/mod.d.ts +8 -0
- package/src/node/crypto-core/javascript/mod.js +24 -0
- package/src/node/crypto-core/javascript/provider.d.ts +2 -0
- package/src/node/crypto-core/javascript/provider.js +43 -0
- package/src/node/crypto-core/pkg/wasm/genation_bridge_crypto_wasm.d.ts +122 -0
- package/src/node/crypto-core/pkg/wasm/genation_bridge_crypto_wasm.js +433 -0
- package/src/node/crypto-core/pkg/wasm/genation_bridge_crypto_wasm_bg.wasm +0 -0
- package/src/node/crypto-core/pkg/wasm/genation_bridge_crypto_wasm_bg.wasm.d.ts +25 -0
- package/src/node/encoding.js +1 -0
- package/src/node/file-key-store.d.ts +6 -0
- package/src/node/file-key-store.js +111 -0
- package/src/node/identity-provider.d.ts +8 -0
- package/src/node/identity-provider.js +57 -0
- package/src/node/identity.js +45 -0
- package/src/node/mod.d.ts +16 -0
- package/src/node/mod.js +17 -0
- package/src/node/relay-runtime.d.ts +11 -0
- package/src/node/relay-runtime.js +11 -0
- package/src/react-native/identity-provider.d.ts +4 -0
- package/src/react-native/identity-provider.js +125 -0
- package/src/react-native/lifecycle.d.ts +8 -0
- package/src/react-native/lifecycle.js +9 -0
- package/src/react-native/mod.d.ts +20 -0
- package/src/react-native/mod.js +36 -0
- package/src/react-native/native-module.d.ts +17 -0
- package/src/react-native/native-module.js +9 -0
- package/src/relay/encoding.js +32 -0
- package/src/relay/frame-channel.d.ts +1 -0
- package/src/relay/frame-channel.js +110 -0
- package/src/relay/identity.d.ts +27 -0
- package/src/relay/identity.js +0 -0
- package/src/relay/runtime.d.ts +8 -0
- package/src/relay/runtime.js +900 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Initiator, Responder } from "../pkg/wasm/genation_bridge_crypto_wasm.d.ts";
|
|
2
|
+
/** Byte-only shared-core exports consumed by the JavaScript SDK adapter. */ export type BridgeCryptoCore = Readonly<{
|
|
3
|
+
Initiator: typeof Initiator;
|
|
4
|
+
Responder: typeof Responder;
|
|
5
|
+
deriveStaticPublic(privateKey: Uint8Array): Uint8Array;
|
|
6
|
+
noiseProfile(): string;
|
|
7
|
+
}>;
|
|
8
|
+
/** Load the prebuilt shared Rust core without invoking Cargo at application runtime. */ export declare const loadBridgeCryptoCore: () => Promise<BridgeCryptoCore>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import initWasm, { derive_static_public, Initiator, noise_profile, Responder } from "../pkg/wasm/genation_bridge_crypto_wasm.js";
|
|
2
|
+
let initialization;
|
|
3
|
+
const wasmSource = async ()=>{
|
|
4
|
+
const url = new URL("../pkg/wasm/genation_bridge_crypto_wasm_bg.wasm", import.meta.url);
|
|
5
|
+
if (url.protocol !== "file:") return url;
|
|
6
|
+
const denoRuntime = globalThis.Deno;
|
|
7
|
+
if (denoRuntime !== undefined) return await denoRuntime.readFile(url);
|
|
8
|
+
const { readFile } = await import("node:fs/promises");
|
|
9
|
+
return new Uint8Array(await readFile(url));
|
|
10
|
+
};
|
|
11
|
+
/** Load the prebuilt shared Rust core without invoking Cargo at application runtime. */ export const loadBridgeCryptoCore = ()=>{
|
|
12
|
+
initialization ??= (async ()=>{
|
|
13
|
+
await initWasm({
|
|
14
|
+
module_or_path: await wasmSource()
|
|
15
|
+
});
|
|
16
|
+
return Object.freeze({
|
|
17
|
+
Initiator,
|
|
18
|
+
Responder,
|
|
19
|
+
deriveStaticPublic: derive_static_public,
|
|
20
|
+
noiseProfile: noise_profile
|
|
21
|
+
});
|
|
22
|
+
})();
|
|
23
|
+
return initialization;
|
|
24
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { bridgeV1NoiseProfile } from "@genation/bridge-contracts/sdk";
|
|
2
|
+
import { loadBridgeCryptoCore } from "./mod.js";
|
|
3
|
+
/** Load the idiomatic JavaScript provider backed by the prebuilt shared Rust core. */ export const loadBridgeE2eeProvider = async ()=>{
|
|
4
|
+
const core = await loadBridgeCryptoCore();
|
|
5
|
+
if (core.noiseProfile() !== bridgeV1NoiseProfile) {
|
|
6
|
+
throw new Error("bridge_crypto_profile_mismatch");
|
|
7
|
+
}
|
|
8
|
+
return Object.freeze({
|
|
9
|
+
profile: bridgeV1NoiseProfile,
|
|
10
|
+
deriveStaticPublic: core.deriveStaticPublic,
|
|
11
|
+
createInitiator: (input)=>{
|
|
12
|
+
const session = new core.Initiator(input.prologue, input.localPrivateKey, input.responderPublicKey);
|
|
13
|
+
let closed = false;
|
|
14
|
+
return Object.freeze({
|
|
15
|
+
beginHandshake: ()=>session.begin_handshake(),
|
|
16
|
+
finishHandshake: (message)=>session.finish_handshake(message),
|
|
17
|
+
encrypt: (aad, plaintext)=>session.encrypt(aad, plaintext),
|
|
18
|
+
decrypt: (aad, ciphertext)=>session.decrypt(aad, ciphertext),
|
|
19
|
+
close: ()=>{
|
|
20
|
+
if (closed) return;
|
|
21
|
+
closed = true;
|
|
22
|
+
session.close();
|
|
23
|
+
session.free();
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
createResponder: (input)=>{
|
|
28
|
+
const session = new core.Responder(input.prologue, input.localPrivateKey, input.initiatorPublicKey);
|
|
29
|
+
let closed = false;
|
|
30
|
+
return Object.freeze({
|
|
31
|
+
acceptHandshake: (message)=>session.accept_handshake(message),
|
|
32
|
+
encrypt: (aad, plaintext)=>session.encrypt(aad, plaintext),
|
|
33
|
+
decrypt: (aad, ciphertext)=>session.decrypt(aad, ciphertext),
|
|
34
|
+
close: ()=>{
|
|
35
|
+
if (closed) return;
|
|
36
|
+
closed = true;
|
|
37
|
+
session.close();
|
|
38
|
+
session.free();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Stateful invoking-peer Noise IK binding.
|
|
6
|
+
*/
|
|
7
|
+
export class Initiator {
|
|
8
|
+
free(): void;
|
|
9
|
+
[Symbol.dispose](): void;
|
|
10
|
+
/**
|
|
11
|
+
* Write handshake message one.
|
|
12
|
+
*/
|
|
13
|
+
begin_handshake(): Uint8Array;
|
|
14
|
+
/**
|
|
15
|
+
* Dispose session state.
|
|
16
|
+
*/
|
|
17
|
+
close(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Decrypt one transport message.
|
|
20
|
+
*/
|
|
21
|
+
decrypt(aad: Uint8Array, ciphertext: Uint8Array): Uint8Array;
|
|
22
|
+
/**
|
|
23
|
+
* Encrypt one transport message.
|
|
24
|
+
*/
|
|
25
|
+
encrypt(aad: Uint8Array, plaintext: Uint8Array): Uint8Array;
|
|
26
|
+
/**
|
|
27
|
+
* Read handshake message two.
|
|
28
|
+
*/
|
|
29
|
+
finish_handshake(message: Uint8Array): void;
|
|
30
|
+
/**
|
|
31
|
+
* Create an invoking-peer state.
|
|
32
|
+
*/
|
|
33
|
+
constructor(prologue: Uint8Array, local_private: Uint8Array, responder_public: Uint8Array);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Stateful exposing-peer Noise IK binding.
|
|
38
|
+
*/
|
|
39
|
+
export class Responder {
|
|
40
|
+
free(): void;
|
|
41
|
+
[Symbol.dispose](): void;
|
|
42
|
+
/**
|
|
43
|
+
* Read handshake one, write handshake two, and enter transport mode.
|
|
44
|
+
*/
|
|
45
|
+
accept_handshake(message: Uint8Array): Uint8Array;
|
|
46
|
+
/**
|
|
47
|
+
* Dispose session state.
|
|
48
|
+
*/
|
|
49
|
+
close(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Decrypt one transport message.
|
|
52
|
+
*/
|
|
53
|
+
decrypt(aad: Uint8Array, ciphertext: Uint8Array): Uint8Array;
|
|
54
|
+
/**
|
|
55
|
+
* Encrypt one transport message.
|
|
56
|
+
*/
|
|
57
|
+
encrypt(aad: Uint8Array, plaintext: Uint8Array): Uint8Array;
|
|
58
|
+
/**
|
|
59
|
+
* Create an exposing-peer state.
|
|
60
|
+
*/
|
|
61
|
+
constructor(prologue: Uint8Array, local_private: Uint8Array, initiator_public: Uint8Array);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Derive the raw X25519 public key for a 32-byte private key.
|
|
66
|
+
*/
|
|
67
|
+
export function derive_static_public(private_key: Uint8Array): Uint8Array;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Return the exact Noise profile compiled into this artifact.
|
|
71
|
+
*/
|
|
72
|
+
export function noise_profile(): string;
|
|
73
|
+
|
|
74
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
75
|
+
|
|
76
|
+
export interface InitOutput {
|
|
77
|
+
readonly memory: WebAssembly.Memory;
|
|
78
|
+
readonly __wbg_initiator_free: (a: number, b: number) => void;
|
|
79
|
+
readonly __wbg_responder_free: (a: number, b: number) => void;
|
|
80
|
+
readonly derive_static_public: (a: number, b: number) => [number, number, number, number];
|
|
81
|
+
readonly initiator_begin_handshake: (a: number) => [number, number, number, number];
|
|
82
|
+
readonly initiator_close: (a: number) => void;
|
|
83
|
+
readonly initiator_decrypt: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
84
|
+
readonly initiator_encrypt: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
85
|
+
readonly initiator_finish_handshake: (a: number, b: number, c: number) => [number, number];
|
|
86
|
+
readonly initiator_new: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
87
|
+
readonly noise_profile: () => [number, number];
|
|
88
|
+
readonly responder_accept_handshake: (a: number, b: number, c: number) => [number, number, number, number];
|
|
89
|
+
readonly responder_close: (a: number) => void;
|
|
90
|
+
readonly responder_decrypt: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
91
|
+
readonly responder_encrypt: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
92
|
+
readonly responder_new: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
93
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
94
|
+
readonly __externref_table_alloc: () => number;
|
|
95
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
96
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
97
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
98
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
99
|
+
readonly __wbindgen_start: () => void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
106
|
+
* a precompiled `WebAssembly.Module`.
|
|
107
|
+
*
|
|
108
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
109
|
+
*
|
|
110
|
+
* @returns {InitOutput}
|
|
111
|
+
*/
|
|
112
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
116
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
117
|
+
*
|
|
118
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
119
|
+
*
|
|
120
|
+
* @returns {Promise<InitOutput>}
|
|
121
|
+
*/
|
|
122
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
/* @ts-self-types="./genation_bridge_crypto_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Stateful invoking-peer Noise IK binding.
|
|
5
|
+
*/
|
|
6
|
+
export class Initiator {
|
|
7
|
+
__destroy_into_raw() {
|
|
8
|
+
const ptr = this.__wbg_ptr;
|
|
9
|
+
this.__wbg_ptr = 0;
|
|
10
|
+
InitiatorFinalization.unregister(this);
|
|
11
|
+
return ptr;
|
|
12
|
+
}
|
|
13
|
+
free() {
|
|
14
|
+
const ptr = this.__destroy_into_raw();
|
|
15
|
+
wasm.__wbg_initiator_free(ptr, 0);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Write handshake message one.
|
|
19
|
+
* @returns {Uint8Array}
|
|
20
|
+
*/
|
|
21
|
+
begin_handshake() {
|
|
22
|
+
const ret = wasm.initiator_begin_handshake(this.__wbg_ptr);
|
|
23
|
+
if (ret[3]) {
|
|
24
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
25
|
+
}
|
|
26
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
27
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
28
|
+
return v1;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Dispose session state.
|
|
32
|
+
*/
|
|
33
|
+
close() {
|
|
34
|
+
wasm.initiator_close(this.__wbg_ptr);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Decrypt one transport message.
|
|
38
|
+
* @param {Uint8Array} aad
|
|
39
|
+
* @param {Uint8Array} ciphertext
|
|
40
|
+
* @returns {Uint8Array}
|
|
41
|
+
*/
|
|
42
|
+
decrypt(aad, ciphertext) {
|
|
43
|
+
const ptr0 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
|
|
44
|
+
const len0 = WASM_VECTOR_LEN;
|
|
45
|
+
const ptr1 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
|
|
46
|
+
const len1 = WASM_VECTOR_LEN;
|
|
47
|
+
const ret = wasm.initiator_decrypt(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
48
|
+
if (ret[3]) {
|
|
49
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
50
|
+
}
|
|
51
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
52
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
53
|
+
return v3;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Encrypt one transport message.
|
|
57
|
+
* @param {Uint8Array} aad
|
|
58
|
+
* @param {Uint8Array} plaintext
|
|
59
|
+
* @returns {Uint8Array}
|
|
60
|
+
*/
|
|
61
|
+
encrypt(aad, plaintext) {
|
|
62
|
+
const ptr0 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
|
|
63
|
+
const len0 = WASM_VECTOR_LEN;
|
|
64
|
+
const ptr1 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
|
|
65
|
+
const len1 = WASM_VECTOR_LEN;
|
|
66
|
+
const ret = wasm.initiator_encrypt(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
67
|
+
if (ret[3]) {
|
|
68
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
69
|
+
}
|
|
70
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
71
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
72
|
+
return v3;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Read handshake message two.
|
|
76
|
+
* @param {Uint8Array} message
|
|
77
|
+
*/
|
|
78
|
+
finish_handshake(message) {
|
|
79
|
+
const ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
|
|
80
|
+
const len0 = WASM_VECTOR_LEN;
|
|
81
|
+
const ret = wasm.initiator_finish_handshake(this.__wbg_ptr, ptr0, len0);
|
|
82
|
+
if (ret[1]) {
|
|
83
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Create an invoking-peer state.
|
|
88
|
+
* @param {Uint8Array} prologue
|
|
89
|
+
* @param {Uint8Array} local_private
|
|
90
|
+
* @param {Uint8Array} responder_public
|
|
91
|
+
*/
|
|
92
|
+
constructor(prologue, local_private, responder_public) {
|
|
93
|
+
const ptr0 = passArray8ToWasm0(prologue, wasm.__wbindgen_malloc);
|
|
94
|
+
const len0 = WASM_VECTOR_LEN;
|
|
95
|
+
const ptr1 = passArray8ToWasm0(local_private, wasm.__wbindgen_malloc);
|
|
96
|
+
const len1 = WASM_VECTOR_LEN;
|
|
97
|
+
const ptr2 = passArray8ToWasm0(responder_public, wasm.__wbindgen_malloc);
|
|
98
|
+
const len2 = WASM_VECTOR_LEN;
|
|
99
|
+
const ret = wasm.initiator_new(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
100
|
+
if (ret[2]) {
|
|
101
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
102
|
+
}
|
|
103
|
+
this.__wbg_ptr = ret[0];
|
|
104
|
+
InitiatorFinalization.register(this, this.__wbg_ptr, this);
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (Symbol.dispose) Initiator.prototype[Symbol.dispose] = Initiator.prototype.free;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Stateful exposing-peer Noise IK binding.
|
|
112
|
+
*/
|
|
113
|
+
export class Responder {
|
|
114
|
+
__destroy_into_raw() {
|
|
115
|
+
const ptr = this.__wbg_ptr;
|
|
116
|
+
this.__wbg_ptr = 0;
|
|
117
|
+
ResponderFinalization.unregister(this);
|
|
118
|
+
return ptr;
|
|
119
|
+
}
|
|
120
|
+
free() {
|
|
121
|
+
const ptr = this.__destroy_into_raw();
|
|
122
|
+
wasm.__wbg_responder_free(ptr, 0);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Read handshake one, write handshake two, and enter transport mode.
|
|
126
|
+
* @param {Uint8Array} message
|
|
127
|
+
* @returns {Uint8Array}
|
|
128
|
+
*/
|
|
129
|
+
accept_handshake(message) {
|
|
130
|
+
const ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
|
|
131
|
+
const len0 = WASM_VECTOR_LEN;
|
|
132
|
+
const ret = wasm.responder_accept_handshake(this.__wbg_ptr, ptr0, len0);
|
|
133
|
+
if (ret[3]) {
|
|
134
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
135
|
+
}
|
|
136
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
137
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
138
|
+
return v2;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Dispose session state.
|
|
142
|
+
*/
|
|
143
|
+
close() {
|
|
144
|
+
wasm.responder_close(this.__wbg_ptr);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Decrypt one transport message.
|
|
148
|
+
* @param {Uint8Array} aad
|
|
149
|
+
* @param {Uint8Array} ciphertext
|
|
150
|
+
* @returns {Uint8Array}
|
|
151
|
+
*/
|
|
152
|
+
decrypt(aad, ciphertext) {
|
|
153
|
+
const ptr0 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
|
|
154
|
+
const len0 = WASM_VECTOR_LEN;
|
|
155
|
+
const ptr1 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
|
|
156
|
+
const len1 = WASM_VECTOR_LEN;
|
|
157
|
+
const ret = wasm.responder_decrypt(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
158
|
+
if (ret[3]) {
|
|
159
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
160
|
+
}
|
|
161
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
162
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
163
|
+
return v3;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Encrypt one transport message.
|
|
167
|
+
* @param {Uint8Array} aad
|
|
168
|
+
* @param {Uint8Array} plaintext
|
|
169
|
+
* @returns {Uint8Array}
|
|
170
|
+
*/
|
|
171
|
+
encrypt(aad, plaintext) {
|
|
172
|
+
const ptr0 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
|
|
173
|
+
const len0 = WASM_VECTOR_LEN;
|
|
174
|
+
const ptr1 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
|
|
175
|
+
const len1 = WASM_VECTOR_LEN;
|
|
176
|
+
const ret = wasm.responder_encrypt(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
177
|
+
if (ret[3]) {
|
|
178
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
179
|
+
}
|
|
180
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
181
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
182
|
+
return v3;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Create an exposing-peer state.
|
|
186
|
+
* @param {Uint8Array} prologue
|
|
187
|
+
* @param {Uint8Array} local_private
|
|
188
|
+
* @param {Uint8Array} initiator_public
|
|
189
|
+
*/
|
|
190
|
+
constructor(prologue, local_private, initiator_public) {
|
|
191
|
+
const ptr0 = passArray8ToWasm0(prologue, wasm.__wbindgen_malloc);
|
|
192
|
+
const len0 = WASM_VECTOR_LEN;
|
|
193
|
+
const ptr1 = passArray8ToWasm0(local_private, wasm.__wbindgen_malloc);
|
|
194
|
+
const len1 = WASM_VECTOR_LEN;
|
|
195
|
+
const ptr2 = passArray8ToWasm0(initiator_public, wasm.__wbindgen_malloc);
|
|
196
|
+
const len2 = WASM_VECTOR_LEN;
|
|
197
|
+
const ret = wasm.responder_new(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
198
|
+
if (ret[2]) {
|
|
199
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
200
|
+
}
|
|
201
|
+
this.__wbg_ptr = ret[0];
|
|
202
|
+
ResponderFinalization.register(this, this.__wbg_ptr, this);
|
|
203
|
+
return this;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (Symbol.dispose) Responder.prototype[Symbol.dispose] = Responder.prototype.free;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Derive the raw X25519 public key for a 32-byte private key.
|
|
210
|
+
* @param {Uint8Array} private_key
|
|
211
|
+
* @returns {Uint8Array}
|
|
212
|
+
*/
|
|
213
|
+
export function derive_static_public(private_key) {
|
|
214
|
+
const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
|
|
215
|
+
const len0 = WASM_VECTOR_LEN;
|
|
216
|
+
const ret = wasm.derive_static_public(ptr0, len0);
|
|
217
|
+
if (ret[3]) {
|
|
218
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
219
|
+
}
|
|
220
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
221
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
222
|
+
return v2;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Return the exact Noise profile compiled into this artifact.
|
|
227
|
+
* @returns {string}
|
|
228
|
+
*/
|
|
229
|
+
export function noise_profile() {
|
|
230
|
+
let deferred1_0;
|
|
231
|
+
let deferred1_1;
|
|
232
|
+
try {
|
|
233
|
+
const ret = wasm.noise_profile();
|
|
234
|
+
deferred1_0 = ret[0];
|
|
235
|
+
deferred1_1 = ret[1];
|
|
236
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
237
|
+
} finally {
|
|
238
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function __wbg_get_imports() {
|
|
242
|
+
const import0 = {
|
|
243
|
+
__proto__: null,
|
|
244
|
+
__wbg_Error_408e67f47ca7b58b: function(arg0, arg1) {
|
|
245
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
246
|
+
return ret;
|
|
247
|
+
},
|
|
248
|
+
__wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
|
|
249
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
250
|
+
},
|
|
251
|
+
__wbg_getRandomValues_a608c4436c19407a: function() { return handleError(function (arg0, arg1) {
|
|
252
|
+
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
253
|
+
}, arguments); },
|
|
254
|
+
__wbindgen_init_externref_table: function() {
|
|
255
|
+
const table = wasm.__wbindgen_externrefs;
|
|
256
|
+
const offset = table.grow(4);
|
|
257
|
+
table.set(0, undefined);
|
|
258
|
+
table.set(offset + 0, undefined);
|
|
259
|
+
table.set(offset + 1, null);
|
|
260
|
+
table.set(offset + 2, true);
|
|
261
|
+
table.set(offset + 3, false);
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
return {
|
|
265
|
+
__proto__: null,
|
|
266
|
+
"./genation_bridge_crypto_wasm_bg.js": import0,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const InitiatorFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
271
|
+
? { register: () => {}, unregister: () => {} }
|
|
272
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_initiator_free(ptr, 1));
|
|
273
|
+
const ResponderFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
274
|
+
? { register: () => {}, unregister: () => {} }
|
|
275
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_responder_free(ptr, 1));
|
|
276
|
+
|
|
277
|
+
function addToExternrefTable0(obj) {
|
|
278
|
+
const idx = wasm.__externref_table_alloc();
|
|
279
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
280
|
+
return idx;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
284
|
+
ptr = ptr >>> 0;
|
|
285
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function getStringFromWasm0(ptr, len) {
|
|
289
|
+
return decodeText(ptr >>> 0, len);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
let cachedUint8ArrayMemory0 = null;
|
|
293
|
+
function getUint8ArrayMemory0() {
|
|
294
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
295
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
296
|
+
}
|
|
297
|
+
return cachedUint8ArrayMemory0;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function handleError(f, args) {
|
|
301
|
+
try {
|
|
302
|
+
return f.apply(this, args);
|
|
303
|
+
} catch (e) {
|
|
304
|
+
const idx = addToExternrefTable0(e);
|
|
305
|
+
wasm.__wbindgen_exn_store(idx);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
310
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
311
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
312
|
+
WASM_VECTOR_LEN = arg.length;
|
|
313
|
+
return ptr;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function takeFromExternrefTable0(idx) {
|
|
317
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
318
|
+
wasm.__externref_table_dealloc(idx);
|
|
319
|
+
return value;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
323
|
+
cachedTextDecoder.decode();
|
|
324
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
325
|
+
let numBytesDecoded = 0;
|
|
326
|
+
function decodeText(ptr, len) {
|
|
327
|
+
numBytesDecoded += len;
|
|
328
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
329
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
330
|
+
cachedTextDecoder.decode();
|
|
331
|
+
numBytesDecoded = len;
|
|
332
|
+
}
|
|
333
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
let WASM_VECTOR_LEN = 0;
|
|
337
|
+
|
|
338
|
+
let wasmModule, wasmInstance, wasm;
|
|
339
|
+
function __wbg_finalize_init(instance, module) {
|
|
340
|
+
wasmInstance = instance;
|
|
341
|
+
wasm = instance.exports;
|
|
342
|
+
wasmModule = module;
|
|
343
|
+
cachedUint8ArrayMemory0 = null;
|
|
344
|
+
wasm.__wbindgen_start();
|
|
345
|
+
return wasm;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
async function __wbg_load(module, imports) {
|
|
349
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
350
|
+
if (!module.ok) {
|
|
351
|
+
throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
355
|
+
try {
|
|
356
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
357
|
+
} catch (e) {
|
|
358
|
+
const validResponse = expectedResponseType(module.type);
|
|
359
|
+
|
|
360
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
361
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
362
|
+
|
|
363
|
+
} else { throw e; }
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const bytes = await module.arrayBuffer();
|
|
368
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
369
|
+
} else {
|
|
370
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
371
|
+
|
|
372
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
373
|
+
return { instance, module };
|
|
374
|
+
} else {
|
|
375
|
+
return instance;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function expectedResponseType(type) {
|
|
380
|
+
switch (type) {
|
|
381
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
382
|
+
}
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function initSync(module) {
|
|
388
|
+
if (wasm !== undefined) return wasm;
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
if (module !== undefined) {
|
|
392
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
393
|
+
({module} = module)
|
|
394
|
+
} else {
|
|
395
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const imports = __wbg_get_imports();
|
|
400
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
401
|
+
module = new WebAssembly.Module(module);
|
|
402
|
+
}
|
|
403
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
404
|
+
return __wbg_finalize_init(instance, module);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
async function __wbg_init(module_or_path) {
|
|
408
|
+
if (wasm !== undefined) return wasm;
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
if (module_or_path !== undefined) {
|
|
412
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
413
|
+
({module_or_path} = module_or_path)
|
|
414
|
+
} else {
|
|
415
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (module_or_path === undefined) {
|
|
420
|
+
module_or_path = new URL('genation_bridge_crypto_wasm_bg.wasm', import.meta.url);
|
|
421
|
+
}
|
|
422
|
+
const imports = __wbg_get_imports();
|
|
423
|
+
|
|
424
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
425
|
+
module_or_path = fetch(module_or_path);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
429
|
+
|
|
430
|
+
return __wbg_finalize_init(instance, module);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export { initSync, __wbg_init as default };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_initiator_free: (a: number, b: number) => void;
|
|
5
|
+
export const __wbg_responder_free: (a: number, b: number) => void;
|
|
6
|
+
export const derive_static_public: (a: number, b: number) => [number, number, number, number];
|
|
7
|
+
export const initiator_begin_handshake: (a: number) => [number, number, number, number];
|
|
8
|
+
export const initiator_close: (a: number) => void;
|
|
9
|
+
export const initiator_decrypt: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
10
|
+
export const initiator_encrypt: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
11
|
+
export const initiator_finish_handshake: (a: number, b: number, c: number) => [number, number];
|
|
12
|
+
export const initiator_new: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
13
|
+
export const noise_profile: () => [number, number];
|
|
14
|
+
export const responder_accept_handshake: (a: number, b: number, c: number) => [number, number, number, number];
|
|
15
|
+
export const responder_close: (a: number) => void;
|
|
16
|
+
export const responder_decrypt: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
17
|
+
export const responder_encrypt: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
18
|
+
export const responder_new: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
19
|
+
export const __wbindgen_exn_store: (a: number) => void;
|
|
20
|
+
export const __externref_table_alloc: () => number;
|
|
21
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
22
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
23
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
24
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
25
|
+
export const __wbindgen_start: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../relay/encoding.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type BridgePeerKeyStore } from "../core/mod.js";
|
|
2
|
+
/** Optional root directory and lock wait policy for the Node.js peer identity store. */ export type NodeFileKeyStoreOptions = Readonly<{
|
|
3
|
+
directory?: string;
|
|
4
|
+
lockTimeoutMs?: number;
|
|
5
|
+
}>;
|
|
6
|
+
/** Creates the SDK-managed atomic owner-only Node.js and Electron file key store. */ export declare const createNodeFileKeyStore: (options?: NodeFileKeyStoreOptions) => BridgePeerKeyStore;
|