Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bicycle-codes/identity

Package Overview
Dependencies
Maintainers
0
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bicycle-codes/identity - npm Package Compare versions

Comparing version 0.9.11 to 0.9.12

11

package.json

@@ -5,3 +5,3 @@ {

"type": "module",
"version": "0.9.11",
"version": "0.9.12",
"main": "dist/index.js",

@@ -30,3 +30,12 @@ "scripts": {

},
"./CONSTANTS": {
"import": "./dist/constants.js",
"require": "./dist/constants.cjs"
},
"./min": "./dist/index.min.js",
"./min/*": {
"import": [
"./dist/*.min.js"
]
},
"./*.min.js": {

@@ -33,0 +42,0 @@ "import": [

@@ -30,2 +30,9 @@ # identity

- [quick example](#quick-example)
- [Examples](#examples)
* [Create a new Identity](#create-a-new-identity)
* [Create a new AES key and encrypt it](#create-a-new-aes-key-and-encrypt-it)
* [Decrypt a key](#decrypt-a-key)
* [Encrypt a message](#encrypt-a-message)
* [Encrypt a message to another Identity](#encrypt-a-message-to-another-identity)
* [Decrypt a message from someone else](#decrypt-a-message-from-someone-else)
- [API](#api)

@@ -135,2 +142,77 @@ * [globals](#globals)

----------------------------------------------------------
## Examples
----------------------------------------------------------
### Create a new Identity
```js
const alice = await Identity.create({
humanName: 'alice',
humanReadableDeviceName: 'phone'
})
```
### Create a new AES key and encrypt it
Create an AES key and encrypt it to an RSA keypair.
```js
import {
aesGenKey,
aesExportKey,
encryptKey,
} from '@bicycle-codes/identity'
import { AES_GCM } from '@bicycle-codes/identity/CONSTANTS'
const alice = await Identity.create({
humanName: 'alice',
humanReadableDeviceName: 'phone'
})
const key = await aesGenKey({ alg: AES_GCM, length: 256 })
const exported = await aesExportKey(key)
const encryptedKey = await encryptKey(key, alice.encryptionKey.publicKey)
```
### Decrypt a key
```js
import { decryptKey } from '@bicycle-codes/identity'
test('decrypt key', async t => {
const decryptedKey = await decryptKey(encryptedKey, alice.encryptionKey)
t.ok(decryptedKey instanceof CryptoKey, 'should return a key')
const exported = await aesExportKey(decryptedKey)
t.equal(uArrs.toString(exported, 'base64pad'), plaintextKey,
'should decrypt to the the same key')
})
```
### Encrypt a message
Create a message that only Alice can decrypt.
```js
test('encrypt a message', async t => {
msg = await alice.encryptMsg('hello world')
t.equal(typeof msg.payload, 'string', 'should create a message object')
t.ok(msg.devices[alice.rootDeviceName],
'should encrypt the message to its author')
})
```
### Encrypt a message to another Identity
```js
const msgToBob = await alice.encryptMsg('hello bob', [
await bob.serialize() // <-- pass in recipients
])
```
### Decrypt a message from someone else
```js
test('decrypt a message from another person', async t => {
const decrypted = await bob.decryptMsg(msgToBob)
t.equal(decrypted, 'hello bob', 'should decrypt the message')
})
```
----------------------------------------------------------
## API

@@ -137,0 +219,0 @@ ----------------------------------------------------------

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc