@unknownncat/swt-libsignal 1.0.6 → 1.0.7
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/crypto.d.ts +1 -1
- package/dist/curve.d.ts +1 -1
- package/dist/fingerprint.js +1 -1
- package/dist/index.d.ts +19 -19
- package/dist/index.js +12 -12
- package/dist/key-helper.d.ts +1 -1
- package/dist/key-helper.js +1 -1
- package/dist/protobuf.d.ts +1 -1
- package/dist/protobuf.js +1 -1
- package/dist/session/builder/index.d.ts +2 -2
- package/dist/session/builder/index.js +2 -2
- package/dist/session/builder/session-builder.d.ts +3 -3
- package/dist/session/builder/session-builder.js +6 -6
- package/dist/session/builder/types.d.ts +1 -1
- package/dist/session/cipher/encoding.d.ts +1 -1
- package/dist/session/cipher/index.d.ts +3 -3
- package/dist/session/cipher/index.js +2 -3
- package/dist/session/cipher/session-cipher.d.ts +2 -2
- package/dist/session/cipher/session-cipher.js +11 -11
- package/dist/session/cipher/types.d.ts +2 -2
- package/dist/session/index.d.ts +5 -3
- package/dist/session/index.js +5 -3
- package/dist/session/record/index.d.ts +3 -3
- package/dist/session/record/index.js +3 -3
- package/dist/session/record/session-entry.d.ts +1 -1
- package/dist/session/record/session-entry.js +1 -1
- package/dist/session/record/session-record.d.ts +2 -2
- package/dist/session/record/session-record.js +4 -4
- package/dist/session/record/types.d.ts +1 -1
- package/dist/session/storage/adapter.d.ts +21 -0
- package/dist/session/storage/adapter.js +57 -0
- package/dist/session/storage/in-memory.d.ts +13 -0
- package/dist/session/storage/in-memory.js +33 -0
- package/dist/session/storage/index.d.ts +19 -0
- package/dist/session/storage/index.js +29 -0
- package/dist/session/storage/migrations.d.ts +2 -0
- package/dist/session/storage/migrations.js +6 -0
- package/dist/session/storage/types.d.ts +18 -0
- package/dist/session/storage/types.js +1 -0
- package/dist/types/index.d.ts +2 -2
- package/package.json +2 -1
package/dist/crypto.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { CryptoAPI } from './types/crypto
|
|
1
|
+
import type { CryptoAPI } from './types/crypto';
|
|
2
2
|
export declare const crypto: CryptoAPI;
|
package/dist/curve.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DHKeyPair, SignalAsymmetricAPI } from './types/asymmetric
|
|
1
|
+
import type { DHKeyPair, SignalAsymmetricAPI } from './types/asymmetric';
|
|
2
2
|
declare function generateKeyPair(): Promise<DHKeyPair>;
|
|
3
3
|
declare function calculateSignature(identityPrivateKey: Uint8Array, data: Uint8Array): Uint8Array<ArrayBufferLike>;
|
|
4
4
|
export declare const signalCrypto: SignalAsymmetricAPI;
|
package/dist/fingerprint.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export { ProtocolAddress } from './protocol_address
|
|
2
|
-
export { SessionRecord, SessionEntry } from './session/record/index
|
|
3
|
-
export type { ChainKey, ChainState, CurrentRatchet, IndexInfo } from './session/record/index
|
|
4
|
-
export { SessionCipher } from './session/cipher/index
|
|
5
|
-
export type { EncryptResult, DecryptResult, DecryptWithSessionResult, SessionCipherStorage } from './session/cipher/index
|
|
6
|
-
export { SessionBuilder } from './session/builder/session-builder
|
|
7
|
-
export type { PreKeyBundle, SessionBuilderStorage, KeyPair, IdentityKeyPair } from './session/builder/index
|
|
8
|
-
export { crypto } from './crypto
|
|
9
|
-
export { signalCrypto, generateKeyPair, calculateSignature } from './curve
|
|
10
|
-
export type { CryptoAPI } from './types/crypto
|
|
11
|
-
export type { SignalAsymmetricAPI, IdentityKeyPair as AsymIdentityKeyPair, DHKeyPair } from './types/asymmetric
|
|
12
|
-
export { generateIdentityKeyPair, generateRegistrationId, generateSignedPreKey, generatePreKey } from './key-helper
|
|
13
|
-
export type { SignedPreKey, PreKey } from './key-helper
|
|
14
|
-
export { FingerprintGenerator } from './fingerprint
|
|
15
|
-
export { SignalError, UntrustedIdentityKeyError, SessionError, MessageCounterError, PreKeyError } from './signal-errors
|
|
16
|
-
export * from
|
|
17
|
-
export type { BaseKeyType as BaseKeyTypeValue } from './ratchet-types
|
|
18
|
-
export { PreKeyWhisperMessage, WhisperMessage } from './protobuf
|
|
19
|
-
export { enqueue } from './job_queue
|
|
1
|
+
export { ProtocolAddress } from './protocol_address';
|
|
2
|
+
export { SessionRecord, SessionEntry } from './session/record/index';
|
|
3
|
+
export type { ChainKey, ChainState, CurrentRatchet, IndexInfo } from './session/record/index';
|
|
4
|
+
export { SessionCipher, WhisperMessageEncoder } from './session/cipher/index';
|
|
5
|
+
export type { EncryptResult, DecryptResult, DecryptWithSessionResult, SessionCipherStorage } from './session/cipher/index';
|
|
6
|
+
export { SessionBuilder } from './session/builder/session-builder';
|
|
7
|
+
export type { PreKeyBundle, SessionBuilderStorage, KeyPair, IdentityKeyPair } from './session/builder/index';
|
|
8
|
+
export { crypto } from './crypto';
|
|
9
|
+
export { signalCrypto, generateKeyPair, calculateSignature } from './curve';
|
|
10
|
+
export type { CryptoAPI } from './types/crypto';
|
|
11
|
+
export type { SignalAsymmetricAPI, IdentityKeyPair as AsymIdentityKeyPair, DHKeyPair } from './types/asymmetric';
|
|
12
|
+
export { generateIdentityKeyPair, generateRegistrationId, generateSignedPreKey, generatePreKey } from './key-helper';
|
|
13
|
+
export type { SignedPreKey, PreKey } from './key-helper';
|
|
14
|
+
export { FingerprintGenerator } from './fingerprint';
|
|
15
|
+
export { SignalError, UntrustedIdentityKeyError, SessionError, MessageCounterError, PreKeyError } from './signal-errors';
|
|
16
|
+
export * from './ratchet-types';
|
|
17
|
+
export type { BaseKeyType as BaseKeyTypeValue } from './ratchet-types';
|
|
18
|
+
export { PreKeyWhisperMessage, WhisperMessage } from './protobuf';
|
|
19
|
+
export { enqueue } from './job_queue';
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export { ProtocolAddress } from './protocol_address
|
|
2
|
-
export { SessionRecord, SessionEntry } from './session/record/index
|
|
3
|
-
export { SessionCipher } from './session/cipher/index
|
|
4
|
-
export { SessionBuilder } from './session/builder/session-builder
|
|
5
|
-
export { crypto } from './crypto
|
|
6
|
-
export { signalCrypto, generateKeyPair, calculateSignature } from './curve
|
|
7
|
-
export { generateIdentityKeyPair, generateRegistrationId, generateSignedPreKey, generatePreKey } from './key-helper
|
|
8
|
-
export { FingerprintGenerator } from './fingerprint
|
|
9
|
-
export { SignalError, UntrustedIdentityKeyError, SessionError, MessageCounterError, PreKeyError } from './signal-errors
|
|
10
|
-
export * from
|
|
11
|
-
export { PreKeyWhisperMessage, WhisperMessage } from './protobuf
|
|
12
|
-
export { enqueue } from './job_queue
|
|
1
|
+
export { ProtocolAddress } from './protocol_address';
|
|
2
|
+
export { SessionRecord, SessionEntry } from './session/record/index';
|
|
3
|
+
export { SessionCipher, WhisperMessageEncoder } from './session/cipher/index';
|
|
4
|
+
export { SessionBuilder } from './session/builder/session-builder';
|
|
5
|
+
export { crypto } from './crypto';
|
|
6
|
+
export { signalCrypto, generateKeyPair, calculateSignature } from './curve';
|
|
7
|
+
export { generateIdentityKeyPair, generateRegistrationId, generateSignedPreKey, generatePreKey } from './key-helper';
|
|
8
|
+
export { FingerprintGenerator } from './fingerprint';
|
|
9
|
+
export { SignalError, UntrustedIdentityKeyError, SessionError, MessageCounterError, PreKeyError } from './signal-errors';
|
|
10
|
+
export * from './ratchet-types';
|
|
11
|
+
export { PreKeyWhisperMessage, WhisperMessage } from './protobuf';
|
|
12
|
+
export { enqueue } from './job_queue';
|
package/dist/key-helper.d.ts
CHANGED
package/dist/key-helper.js
CHANGED
package/dist/protobuf.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { PreKeyWhisperMessage, WhisperMessage } from "./generated/WhisperTextProtocol
|
|
1
|
+
export { PreKeyWhisperMessage, WhisperMessage } from "./generated/WhisperTextProtocol";
|
package/dist/protobuf.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
export { PreKeyWhisperMessage, WhisperMessage } from "./generated/WhisperTextProtocol
|
|
2
|
+
export { PreKeyWhisperMessage, WhisperMessage } from "./generated/WhisperTextProtocol";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './types
|
|
2
|
-
export * from './session-builder
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './session-builder';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './types
|
|
2
|
-
export * from './session-builder
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './session-builder';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ProtocolAddress } from '../../protocol_address
|
|
2
|
-
import { SessionRecord } from '../record/index
|
|
3
|
-
import type { PreKeyBundle, PreKeyWhisperMessage, SessionBuilderStorage } from './types
|
|
1
|
+
import type { ProtocolAddress } from '../../protocol_address';
|
|
2
|
+
import { SessionRecord } from '../record/index';
|
|
3
|
+
import type { PreKeyBundle, PreKeyWhisperMessage, SessionBuilderStorage } from './types';
|
|
4
4
|
export declare class SessionBuilder {
|
|
5
5
|
private readonly addr;
|
|
6
6
|
private readonly storage;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { BaseKeyType, ChainType } from "../../ratchet-types
|
|
2
|
-
import { SessionRecord } from '../record/index
|
|
3
|
-
import { crypto } from '../../crypto
|
|
4
|
-
import { signalCrypto } from '../../curve
|
|
5
|
-
import { UntrustedIdentityKeyError, PreKeyError } from '../../signal-errors
|
|
6
|
-
import { enqueue } from '../../job_queue
|
|
1
|
+
import { BaseKeyType, ChainType } from "../../ratchet-types";
|
|
2
|
+
import { SessionRecord } from '../record/index';
|
|
3
|
+
import { crypto } from '../../crypto';
|
|
4
|
+
import { signalCrypto } from '../../curve';
|
|
5
|
+
import { UntrustedIdentityKeyError, PreKeyError } from '../../signal-errors';
|
|
6
|
+
import { enqueue } from '../../job_queue';
|
|
7
7
|
export class SessionBuilder {
|
|
8
8
|
addr;
|
|
9
9
|
storage;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WhisperMessageProto, PreKeyWhisperMessageProto } from './types
|
|
1
|
+
import type { WhisperMessageProto, PreKeyWhisperMessageProto } from './types';
|
|
2
2
|
export declare class WhisperMessageEncoder {
|
|
3
3
|
static encodeWhisperMessage(msg: WhisperMessageProto): Uint8Array;
|
|
4
4
|
static decodeWhisperMessage(buf: Uint8Array): WhisperMessageProto;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export * from './
|
|
1
|
+
export { WhisperMessageEncoder } from "./encoding";
|
|
2
|
+
export { SessionCipher } from './session-cipher';
|
|
3
|
+
export type * from './types';
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export * from './session-cipher.js';
|
|
1
|
+
export { WhisperMessageEncoder } from "./encoding";
|
|
2
|
+
export { SessionCipher } from './session-cipher';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { EncryptResult, SessionCipherStorage } from './types
|
|
2
|
-
import { ProtocolAddress } from '../../protocol_address
|
|
1
|
+
import type { EncryptResult, SessionCipherStorage } from './types';
|
|
2
|
+
import { ProtocolAddress } from '../../protocol_address';
|
|
3
3
|
export declare class SessionCipher {
|
|
4
4
|
private readonly addr;
|
|
5
5
|
private readonly addrStr;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { PROTOCOL_VERSION } from '../constants
|
|
2
|
-
import { WhisperMessageEncoder } from './encoding
|
|
3
|
-
import { assertUint8, toBase64 } from '../utils
|
|
4
|
-
import { ChainType } from "../../ratchet-types
|
|
5
|
-
import { ProtocolAddress } from '../../protocol_address
|
|
6
|
-
import { SessionBuilder } from '../builder/session-builder
|
|
7
|
-
import { SessionRecord } from '../record/index
|
|
8
|
-
import { crypto } from '../../crypto
|
|
9
|
-
import { signalCrypto } from '../../curve
|
|
10
|
-
import { SessionError, UntrustedIdentityKeyError, MessageCounterError } from '../../signal-errors
|
|
11
|
-
import { enqueue } from '../../job_queue
|
|
1
|
+
import { PROTOCOL_VERSION } from '../constants';
|
|
2
|
+
import { WhisperMessageEncoder } from './encoding';
|
|
3
|
+
import { assertUint8, toBase64 } from '../utils';
|
|
4
|
+
import { ChainType } from "../../ratchet-types";
|
|
5
|
+
import { ProtocolAddress } from '../../protocol_address';
|
|
6
|
+
import { SessionBuilder } from '../builder/session-builder';
|
|
7
|
+
import { SessionRecord } from '../record/index';
|
|
8
|
+
import { crypto } from '../../crypto';
|
|
9
|
+
import { signalCrypto } from '../../curve';
|
|
10
|
+
import { SessionError, UntrustedIdentityKeyError, MessageCounterError } from '../../signal-errors';
|
|
11
|
+
import { enqueue } from '../../job_queue';
|
|
12
12
|
export class SessionCipher {
|
|
13
13
|
addr;
|
|
14
14
|
addrStr;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SessionEntry } from "../record/session-entry
|
|
2
|
-
import type { SessionRecord } from "../record/session-record
|
|
1
|
+
import type { SessionEntry } from "../record/session-entry";
|
|
2
|
+
import type { SessionRecord } from "../record/session-record";
|
|
3
3
|
export interface EncryptResult {
|
|
4
4
|
type: number;
|
|
5
5
|
body: Uint8Array;
|
package/dist/session/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
1
|
+
export { WhisperMessageEncoder } from "./cipher/index";
|
|
2
|
+
export * from "./cipher/index";
|
|
3
|
+
export * from "./record/index";
|
|
4
|
+
export * from "./builder/index";
|
|
5
|
+
export * from "./storage/index";
|
package/dist/session/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
1
|
+
export { WhisperMessageEncoder } from "./cipher/index";
|
|
2
|
+
export * from "./cipher/index";
|
|
3
|
+
export * from "./record/index";
|
|
4
|
+
export * from "./builder/index";
|
|
5
|
+
export * from "./storage/index";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './types
|
|
2
|
-
export * from './session-entry
|
|
3
|
-
export * from './session-record
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './session-entry';
|
|
3
|
+
export * from './session-record';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './types
|
|
2
|
-
export * from './session-entry
|
|
3
|
-
export * from './session-record
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './session-entry';
|
|
3
|
+
export * from './session-record';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChainState, CurrentRatchet, IndexInfo, PendingPreKey, SerializedSessionEntry } from './types
|
|
1
|
+
import type { ChainState, CurrentRatchet, IndexInfo, PendingPreKey, SerializedSessionEntry } from './types';
|
|
2
2
|
export declare class SessionEntry {
|
|
3
3
|
registrationId: number;
|
|
4
4
|
currentRatchet: CurrentRatchet;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SerializedSessionRecord } from './types
|
|
2
|
-
import { SessionEntry } from './session-entry
|
|
1
|
+
import type { SerializedSessionRecord } from './types';
|
|
2
|
+
import { SessionEntry } from './session-entry';
|
|
3
3
|
export declare class SessionRecord {
|
|
4
4
|
sessions: Record<string, SessionEntry>;
|
|
5
5
|
version: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { SessionEntry } from './session-entry
|
|
2
|
-
import { CLOSED_SESSIONS_MAX, SESSION_RECORD_VERSION } from '../constants
|
|
3
|
-
import { assertUint8, toBase64 } from '../utils
|
|
4
|
-
import { BaseKeyType } from "../../ratchet-types
|
|
1
|
+
import { SessionEntry } from './session-entry';
|
|
2
|
+
import { CLOSED_SESSIONS_MAX, SESSION_RECORD_VERSION } from '../constants';
|
|
3
|
+
import { assertUint8, toBase64 } from '../utils';
|
|
4
|
+
import { BaseKeyType } from "../../ratchet-types";
|
|
5
5
|
export class SessionRecord {
|
|
6
6
|
sessions = {};
|
|
7
7
|
version = SESSION_RECORD_VERSION;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { StorageAdapter } from './types';
|
|
2
|
+
import { SessionRecord } from '../record/index';
|
|
3
|
+
export declare function createSessionStorage(adapter: StorageAdapter): {
|
|
4
|
+
isTrustedIdentity(addressName: string, identityKey: Uint8Array): Promise<boolean>;
|
|
5
|
+
loadSession(addressName: string): Promise<SessionRecord | undefined>;
|
|
6
|
+
storeSession(addressName: string, record: ReturnType<(typeof SessionRecord)["prototype"]["serialize"]>): Promise<void>;
|
|
7
|
+
getOurIdentity(): Promise<{
|
|
8
|
+
pubKey: Uint8Array<ArrayBufferLike>;
|
|
9
|
+
privKey: Uint8Array<ArrayBufferLike>;
|
|
10
|
+
}>;
|
|
11
|
+
loadPreKey(preKeyId: number): Promise<{
|
|
12
|
+
pubKey: Uint8Array<ArrayBufferLike>;
|
|
13
|
+
privKey: Uint8Array<ArrayBufferLike>;
|
|
14
|
+
} | undefined>;
|
|
15
|
+
loadSignedPreKey(signedPreKeyId: number): Promise<{
|
|
16
|
+
pubKey: Uint8Array<ArrayBufferLike>;
|
|
17
|
+
privKey: Uint8Array<ArrayBufferLike>;
|
|
18
|
+
} | undefined>;
|
|
19
|
+
removePreKey(preKeyId: number): Promise<void>;
|
|
20
|
+
getOurRegistrationId(): Promise<number>;
|
|
21
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { SessionRecord } from '../record/index';
|
|
2
|
+
import { toBase64, fromBase64 } from '../utils';
|
|
3
|
+
function sessionKey(addr) { return `session:${addr}`; }
|
|
4
|
+
function preKeyKey(id) { return `prekey:${id}`; }
|
|
5
|
+
function signedPreKeyKey(id) { return `signedprekey:${id}`; }
|
|
6
|
+
function identityKeyF(addr) { return `identity:${addr}`; }
|
|
7
|
+
const OUR_IDENTITY = 'our_identity';
|
|
8
|
+
const REG_ID = 'registration_id';
|
|
9
|
+
export function createSessionStorage(adapter) {
|
|
10
|
+
return {
|
|
11
|
+
async isTrustedIdentity(addressName, identityKey) {
|
|
12
|
+
const stored = await adapter.get(identityKeyF(addressName));
|
|
13
|
+
const encoded = toBase64(identityKey);
|
|
14
|
+
if (!stored) {
|
|
15
|
+
await adapter.set(identityKeyF(addressName), encoded);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return stored === encoded;
|
|
19
|
+
},
|
|
20
|
+
async loadSession(addressName) {
|
|
21
|
+
const data = await adapter.get(sessionKey(addressName));
|
|
22
|
+
if (!data)
|
|
23
|
+
return undefined;
|
|
24
|
+
return SessionRecord.deserialize(data);
|
|
25
|
+
},
|
|
26
|
+
async storeSession(addressName, record) {
|
|
27
|
+
await adapter.set(sessionKey(addressName), record);
|
|
28
|
+
},
|
|
29
|
+
async getOurIdentity() {
|
|
30
|
+
const data = await adapter.get(OUR_IDENTITY);
|
|
31
|
+
if (!data)
|
|
32
|
+
throw new Error('Our identity not found in storage');
|
|
33
|
+
return { pubKey: fromBase64(data.pubKey), privKey: fromBase64(data.privKey) };
|
|
34
|
+
},
|
|
35
|
+
async loadPreKey(preKeyId) {
|
|
36
|
+
const data = await adapter.get(preKeyKey(preKeyId));
|
|
37
|
+
if (!data)
|
|
38
|
+
return undefined;
|
|
39
|
+
return { pubKey: fromBase64(data.pubKey), privKey: fromBase64(data.privKey) };
|
|
40
|
+
},
|
|
41
|
+
async loadSignedPreKey(signedPreKeyId) {
|
|
42
|
+
const data = await adapter.get(signedPreKeyKey(signedPreKeyId));
|
|
43
|
+
if (!data)
|
|
44
|
+
return undefined;
|
|
45
|
+
return { pubKey: fromBase64(data.pubKey), privKey: fromBase64(data.privKey) };
|
|
46
|
+
},
|
|
47
|
+
async removePreKey(preKeyId) {
|
|
48
|
+
await adapter.delete(preKeyKey(preKeyId));
|
|
49
|
+
},
|
|
50
|
+
async getOurRegistrationId() {
|
|
51
|
+
const v = await adapter.get(REG_ID);
|
|
52
|
+
if (typeof v !== 'number')
|
|
53
|
+
throw new Error('registration id missing');
|
|
54
|
+
return v;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { StorageAdapter, BatchOp } from './types';
|
|
2
|
+
export declare class InMemoryStorage implements StorageAdapter {
|
|
3
|
+
private store;
|
|
4
|
+
name: string;
|
|
5
|
+
constructor(initial?: Record<string, any>);
|
|
6
|
+
get<T = any>(key: string): Promise<T | undefined>;
|
|
7
|
+
set<T = any>(key: string, value: T): Promise<void>;
|
|
8
|
+
delete(key: string): Promise<void>;
|
|
9
|
+
batch(ops: BatchOp[]): Promise<void>;
|
|
10
|
+
clear(): Promise<void>;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare function createInMemoryStorage(initial?: Record<string, any>): InMemoryStorage;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export class InMemoryStorage {
|
|
2
|
+
store = new Map();
|
|
3
|
+
name = 'in-memory';
|
|
4
|
+
constructor(initial) {
|
|
5
|
+
if (initial)
|
|
6
|
+
Object.entries(initial).forEach(([k, v]) => this.store.set(k, v));
|
|
7
|
+
}
|
|
8
|
+
async get(key) {
|
|
9
|
+
return this.store.has(key) ? this.store.get(key) : undefined;
|
|
10
|
+
}
|
|
11
|
+
async set(key, value) {
|
|
12
|
+
this.store.set(key, value);
|
|
13
|
+
}
|
|
14
|
+
async delete(key) {
|
|
15
|
+
this.store.delete(key);
|
|
16
|
+
}
|
|
17
|
+
async batch(ops) {
|
|
18
|
+
for (const op of ops) {
|
|
19
|
+
if (op.type === 'put')
|
|
20
|
+
this.store.set(op.key, op.value);
|
|
21
|
+
else
|
|
22
|
+
this.store.delete(op.key);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async clear() {
|
|
26
|
+
this.store.clear();
|
|
27
|
+
}
|
|
28
|
+
async close() {
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function createInMemoryStorage(initial) {
|
|
32
|
+
return new InMemoryStorage(initial);
|
|
33
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './in-memory';
|
|
3
|
+
export * from './migrations';
|
|
4
|
+
export * from './adapter';
|
|
5
|
+
import { StorageAdapter } from './types';
|
|
6
|
+
export declare class StorageManager {
|
|
7
|
+
adapter: StorageAdapter;
|
|
8
|
+
constructor(adapter: StorageAdapter);
|
|
9
|
+
get<T = any>(key: string): Promise<T | undefined>;
|
|
10
|
+
set<T = any>(key: string, value: T): Promise<void>;
|
|
11
|
+
delete(key: string): Promise<void>;
|
|
12
|
+
batch(ops: Array<{
|
|
13
|
+
type: 'put' | 'del';
|
|
14
|
+
key: string;
|
|
15
|
+
value?: any;
|
|
16
|
+
}>): Promise<void>;
|
|
17
|
+
close(): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export declare function createStorageManager(adapter: StorageAdapter): StorageManager;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './in-memory';
|
|
3
|
+
export * from './migrations';
|
|
4
|
+
export * from './adapter';
|
|
5
|
+
export class StorageManager {
|
|
6
|
+
adapter;
|
|
7
|
+
constructor(adapter) {
|
|
8
|
+
this.adapter = adapter;
|
|
9
|
+
}
|
|
10
|
+
get(key) {
|
|
11
|
+
return this.adapter.get(key);
|
|
12
|
+
}
|
|
13
|
+
set(key, value) {
|
|
14
|
+
return this.adapter.set(key, value);
|
|
15
|
+
}
|
|
16
|
+
delete(key) {
|
|
17
|
+
return this.adapter.delete(key);
|
|
18
|
+
}
|
|
19
|
+
batch(ops) {
|
|
20
|
+
return this.adapter.batch(ops);
|
|
21
|
+
}
|
|
22
|
+
async close() {
|
|
23
|
+
if (this.adapter.close)
|
|
24
|
+
return this.adapter.close();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function createStorageManager(adapter) {
|
|
28
|
+
return new StorageManager(adapter);
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type BatchOp = {
|
|
2
|
+
type: 'put' | 'del';
|
|
3
|
+
key: string;
|
|
4
|
+
value?: any;
|
|
5
|
+
};
|
|
6
|
+
export interface StorageAdapter {
|
|
7
|
+
get<T = any>(key: string): Promise<T | undefined>;
|
|
8
|
+
set<T = any>(key: string, value: T): Promise<void>;
|
|
9
|
+
delete(key: string): Promise<void>;
|
|
10
|
+
batch(ops: BatchOp[]): Promise<void>;
|
|
11
|
+
clear?(): Promise<void>;
|
|
12
|
+
close?(): Promise<void>;
|
|
13
|
+
name?: string;
|
|
14
|
+
migrate?(fromVersion: number, toVersion: number): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export interface StorageManagerOptions {
|
|
17
|
+
adapter: StorageAdapter;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./asymmetric
|
|
2
|
-
export * from "./crypto
|
|
1
|
+
export * from "./asymmetric";
|
|
2
|
+
export * from "./crypto";
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unknownncat/swt-libsignal",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Libsignal reimplementation using libsodium",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
+
"license": "MIT",
|
|
8
9
|
"publishConfig": {
|
|
9
10
|
"access": "public"
|
|
10
11
|
},
|