-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refactor user preferences exports for web
- Loading branch information
Showing
4 changed files
with
98 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { | ||
// eslint-disable-next-line camelcase | ||
generate_private_preferences_topic, | ||
// eslint-disable-next-line camelcase | ||
user_preferences_decrypt, | ||
// eslint-disable-next-line camelcase | ||
user_preferences_encrypt, | ||
} from '@xmtp/user-preferences-bindings-wasm' | ||
import { PrivateKey } from '../crypto' | ||
|
||
export async function userPreferencesEncrypt( | ||
identityKey: PrivateKey, | ||
payload: Uint8Array | ||
) { | ||
const publicKey = identityKey.publicKey.secp256k1Uncompressed.bytes | ||
const privateKey = identityKey.secp256k1.bytes | ||
// eslint-disable-next-line camelcase | ||
return user_preferences_encrypt(publicKey, privateKey, payload) | ||
} | ||
|
||
export async function userPreferencesDecrypt( | ||
identityKey: PrivateKey, | ||
payload: Uint8Array | ||
) { | ||
const publicKey = identityKey.publicKey.secp256k1Uncompressed.bytes | ||
const privateKey = identityKey.secp256k1.bytes | ||
// eslint-disable-next-line camelcase | ||
return user_preferences_decrypt(publicKey, privateKey, payload) | ||
} | ||
|
||
export async function generateUserPreferencesTopic(identityKey: PrivateKey) { | ||
const privateKey = identityKey.secp256k1.bytes | ||
// eslint-disable-next-line camelcase | ||
return generate_private_preferences_topic(privateKey) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/*********************************************************************************************** | ||
* DO NOT IMPORT THIS FILE DIRECTLY | ||
***********************************************************************************************/ | ||
|
||
import init, { | ||
// eslint-disable-next-line camelcase | ||
generate_private_preferences_topic, | ||
// eslint-disable-next-line camelcase | ||
user_preferences_decrypt, | ||
// eslint-disable-next-line camelcase | ||
user_preferences_encrypt, | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
} from '@xmtp/user-preferences-bindings-wasm/web' | ||
import { PrivateKey } from './PrivateKey' | ||
|
||
export async function userPreferencesEncrypt( | ||
identityKey: PrivateKey, | ||
payload: Uint8Array | ||
) { | ||
// wait for WASM to be initialized | ||
await init() | ||
const publicKey = identityKey.publicKey.secp256k1Uncompressed.bytes | ||
const privateKey = identityKey.secp256k1.bytes | ||
// eslint-disable-next-line camelcase | ||
return user_preferences_encrypt(publicKey, privateKey, payload) | ||
} | ||
|
||
export async function userPreferencesDecrypt( | ||
identityKey: PrivateKey, | ||
payload: Uint8Array | ||
) { | ||
// wait for WASM to be initialized | ||
await init() | ||
const publicKey = identityKey.publicKey.secp256k1Uncompressed.bytes | ||
const privateKey = identityKey.secp256k1.bytes | ||
// eslint-disable-next-line camelcase | ||
return user_preferences_decrypt(publicKey, privateKey, payload) | ||
} | ||
|
||
export async function generateUserPreferencesTopic(identityKey: PrivateKey) { | ||
// wait for WASM to be initialized | ||
await init() | ||
const privateKey = identityKey.secp256k1.bytes | ||
// eslint-disable-next-line camelcase | ||
return generate_private_preferences_topic(privateKey) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters