@atproto/crypto 0.1.0 → 0.2.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/dist/did.d.ts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1885 -2533
- package/dist/index.js.map +4 -4
- package/dist/multibase.d.ts +2 -0
- package/dist/p256/keypair.d.ts +9 -9
- package/dist/p256/operations.d.ts +1 -3
- package/dist/random.d.ts +3 -2
- package/dist/secp256k1/operations.d.ts +1 -0
- package/dist/sha.d.ts +0 -2
- package/dist/types.d.ts +1 -0
- package/package.json +10 -7
- package/src/did.ts +4 -8
- package/src/index.ts +0 -1
- package/src/multibase.ts +27 -0
- package/src/p256/encoding.ts +5 -72
- package/src/p256/keypair.ts +25 -41
- package/src/p256/operations.ts +6 -45
- package/src/random.ts +15 -8
- package/src/secp256k1/encoding.ts +3 -5
- package/src/secp256k1/keypair.ts +7 -5
- package/src/secp256k1/operations.ts +12 -3
- package/src/sha.ts +2 -19
- package/src/types.ts +1 -0
- package/tests/did.test.ts +8 -22
- package/tests/key-compression.test.ts +3 -3
- package/tests/keypairs.test.ts +71 -0
- package/tests/signature-fixtures.json +34 -0
- package/tests/signatures.test.ts +161 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +1 -4
- package/dist/const.d.ts +0 -5
- package/dist/p256/encoding.d.ts +0 -2
- package/dist/p256/plugin.d.ts +0 -3
- package/dist/plugins.d.ts +0 -2
- package/dist/secp256k1/encoding.d.ts +0 -2
- package/dist/secp256k1/keypair.d.ts +0 -20
- package/dist/secp256k1/plugin.d.ts +0 -3
- package/dist/src/aes.d.ts +0 -8
- package/dist/src/const.d.ts +0 -5
- package/dist/src/did.d.ts +0 -7
- package/dist/src/index.d.ts +0 -12
- package/dist/src/multibase.d.ts +0 -1
- package/dist/src/p256/ecdh.d.ts +0 -11
- package/dist/src/p256/ecdsa.d.ts +0 -19
- package/dist/src/p256/encoding.d.ts +0 -2
- package/dist/src/p256/keypair.d.ts +0 -19
- package/dist/src/p256/operations.d.ts +0 -4
- package/dist/src/p256/plugin.d.ts +0 -3
- package/dist/src/plugins.d.ts +0 -2
- package/dist/src/random.d.ts +0 -4
- package/dist/src/secp256k1/encoding.d.ts +0 -2
- package/dist/src/secp256k1/keypair.d.ts +0 -19
- package/dist/src/secp256k1/operations.d.ts +0 -1
- package/dist/src/secp256k1/plugin.d.ts +0 -3
- package/dist/src/sha.d.ts +0 -3
- package/dist/src/types.d.ts +0 -13
- package/dist/src/verify.d.ts +0 -1
- package/dist/verify.d.ts +0 -2
- package/src/aes.ts +0 -64
- package/tests/export.test.ts +0 -50
package/dist/verify.d.ts
DELETED
package/src/aes.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { webcrypto } from 'one-webcrypto'
|
|
2
|
-
import * as uint8arrays from 'uint8arrays'
|
|
3
|
-
|
|
4
|
-
import * as random from './random'
|
|
5
|
-
|
|
6
|
-
export class AesKey {
|
|
7
|
-
private key: CryptoKey
|
|
8
|
-
constructor(key: CryptoKey) {
|
|
9
|
-
this.key = key
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
static async create(): Promise<AesKey> {
|
|
13
|
-
const key = await webcrypto.subtle.generateKey(
|
|
14
|
-
{
|
|
15
|
-
name: 'AES-GCM',
|
|
16
|
-
length: 256,
|
|
17
|
-
},
|
|
18
|
-
true,
|
|
19
|
-
['encrypt', 'decrypt'],
|
|
20
|
-
)
|
|
21
|
-
return new AesKey(key)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// utf8 data -> base64pad cipher
|
|
25
|
-
// returns base64 encrypted data with iv prepended
|
|
26
|
-
async encrypt(data: string): Promise<string> {
|
|
27
|
-
const iv = random.randomIV()
|
|
28
|
-
const dataBytes = uint8arrays.fromString(data, 'utf8')
|
|
29
|
-
const buf = await webcrypto.subtle.encrypt(
|
|
30
|
-
{
|
|
31
|
-
name: 'AES-GCM',
|
|
32
|
-
iv,
|
|
33
|
-
},
|
|
34
|
-
this.key,
|
|
35
|
-
dataBytes,
|
|
36
|
-
)
|
|
37
|
-
const encryptedBytes = new Uint8Array(buf)
|
|
38
|
-
const encrypted = uint8arrays.toString(
|
|
39
|
-
uint8arrays.concat([iv, encryptedBytes]),
|
|
40
|
-
'base64pad',
|
|
41
|
-
)
|
|
42
|
-
return encrypted
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// base64pad cipher -> utf8 data
|
|
46
|
-
// expects base64 encrypted data with iv prepended
|
|
47
|
-
async decrypt(data: string): Promise<string> {
|
|
48
|
-
const dataBytes = uint8arrays.fromString(data, 'base64pad')
|
|
49
|
-
const iv = dataBytes.slice(0, 12)
|
|
50
|
-
const encrypted = dataBytes.slice(12)
|
|
51
|
-
const buf = await webcrypto.subtle.decrypt(
|
|
52
|
-
{
|
|
53
|
-
name: 'AES-GCM',
|
|
54
|
-
iv,
|
|
55
|
-
},
|
|
56
|
-
this.key,
|
|
57
|
-
encrypted,
|
|
58
|
-
)
|
|
59
|
-
const decryptedBytes = new Uint8Array(buf)
|
|
60
|
-
return uint8arrays.toString(decryptedBytes, 'utf8')
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export default AesKey
|
package/tests/export.test.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import EcdsaKeypair from '../src/p256/keypair'
|
|
2
|
-
import Secp256k1Keypair from '../src/secp256k1/keypair'
|
|
3
|
-
import * as p256 from '../src/p256/operations'
|
|
4
|
-
import * as secp from '../src/secp256k1/operations'
|
|
5
|
-
|
|
6
|
-
describe('exports and reimports keys', () => {
|
|
7
|
-
describe('secp256k1', () => {
|
|
8
|
-
let keypair: Secp256k1Keypair
|
|
9
|
-
let imported: Secp256k1Keypair
|
|
10
|
-
|
|
11
|
-
it('has the same DID', async () => {
|
|
12
|
-
keypair = await Secp256k1Keypair.create({ exportable: true })
|
|
13
|
-
const exported = await keypair.export()
|
|
14
|
-
imported = await Secp256k1Keypair.import(exported, { exportable: true })
|
|
15
|
-
|
|
16
|
-
expect(keypair.did()).toBe(imported.did())
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
it('produces a valid signature', async () => {
|
|
20
|
-
const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])
|
|
21
|
-
const sig = await imported.sign(data)
|
|
22
|
-
|
|
23
|
-
const validSig = await secp.verifyDidSig(keypair.did(), data, sig)
|
|
24
|
-
|
|
25
|
-
expect(validSig).toBeTruthy()
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
describe('P-256', () => {
|
|
30
|
-
let keypair: EcdsaKeypair
|
|
31
|
-
let imported: EcdsaKeypair
|
|
32
|
-
|
|
33
|
-
it('has the same DID', async () => {
|
|
34
|
-
keypair = await EcdsaKeypair.create({ exportable: true })
|
|
35
|
-
const exported = await keypair.export()
|
|
36
|
-
imported = await EcdsaKeypair.import(exported, { exportable: true })
|
|
37
|
-
|
|
38
|
-
expect(keypair.did()).toBe(imported.did())
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('produces a valid signature', async () => {
|
|
42
|
-
const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])
|
|
43
|
-
const sig = await imported.sign(data)
|
|
44
|
-
|
|
45
|
-
const validSig = await p256.verifyDidSig(keypair.did(), data, sig)
|
|
46
|
-
|
|
47
|
-
expect(validSig).toBeTruthy()
|
|
48
|
-
})
|
|
49
|
-
})
|
|
50
|
-
})
|