@peerbit/crypto 1.0.1
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/LICENSE +202 -0
- package/README.md +3 -0
- package/lib/esm/bytes.d.ts +5 -0
- package/lib/esm/bytes.js +15 -0
- package/lib/esm/bytes.js.map +1 -0
- package/lib/esm/ed25519-sign-browser.d.ts +5 -0
- package/lib/esm/ed25519-sign-browser.js +27 -0
- package/lib/esm/ed25519-sign-browser.js.map +1 -0
- package/lib/esm/ed25519-sign.d.ts +5 -0
- package/lib/esm/ed25519-sign.js +64 -0
- package/lib/esm/ed25519-sign.js.map +1 -0
- package/lib/esm/ed25519.d.ts +41 -0
- package/lib/esm/ed25519.js +181 -0
- package/lib/esm/ed25519.js.map +1 -0
- package/lib/esm/encryption.d.ts +76 -0
- package/lib/esm/encryption.js +350 -0
- package/lib/esm/encryption.js.map +1 -0
- package/lib/esm/errors.d.ts +3 -0
- package/lib/esm/errors.js +6 -0
- package/lib/esm/errors.js.map +1 -0
- package/lib/esm/hash-browser.d.ts +4 -0
- package/lib/esm/hash-browser.js +7 -0
- package/lib/esm/hash-browser.js.map +1 -0
- package/lib/esm/hash.d.ts +4 -0
- package/lib/esm/hash.js +6 -0
- package/lib/esm/hash.js.map +1 -0
- package/lib/esm/index.d.ts +14 -0
- package/lib/esm/index.js +15 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/key.d.ts +44 -0
- package/lib/esm/key.js +51 -0
- package/lib/esm/key.js.map +1 -0
- package/lib/esm/keychain.d.ts +30 -0
- package/lib/esm/keychain.js +142 -0
- package/lib/esm/keychain.js.map +1 -0
- package/lib/esm/libp2p.d.ts +5 -0
- package/lib/esm/libp2p.js +21 -0
- package/lib/esm/libp2p.js.map +1 -0
- package/lib/esm/prehash.d.ts +6 -0
- package/lib/esm/prehash.js +32 -0
- package/lib/esm/prehash.js.map +1 -0
- package/lib/esm/random-browser.d.ts +1 -0
- package/lib/esm/random-browser.js +2 -0
- package/lib/esm/random-browser.js.map +1 -0
- package/lib/esm/random.d.ts +2 -0
- package/lib/esm/random.js +3 -0
- package/lib/esm/random.js.map +1 -0
- package/lib/esm/sepc256k1.d.ts +42 -0
- package/lib/esm/sepc256k1.js +194 -0
- package/lib/esm/sepc256k1.js.map +1 -0
- package/lib/esm/signature.d.ts +34 -0
- package/lib/esm/signature.js +283 -0
- package/lib/esm/signature.js.map +1 -0
- package/lib/esm/signer.d.ts +10 -0
- package/lib/esm/signer.js +2 -0
- package/lib/esm/signer.js.map +1 -0
- package/lib/esm/utils.d.ts +4 -0
- package/lib/esm/utils.js +10 -0
- package/lib/esm/utils.js.map +1 -0
- package/lib/esm/x25519.d.ts +38 -0
- package/lib/esm/x25519.js +158 -0
- package/lib/esm/x25519.js.map +1 -0
- package/package.json +55 -0
- package/src/bytes.ts +12 -0
- package/src/ed25519-sign-browser.ts +43 -0
- package/src/ed25519-sign.ts +83 -0
- package/src/ed25519.ts +194 -0
- package/src/encryption.ts +376 -0
- package/src/errors.ts +5 -0
- package/src/hash-browser.ts +10 -0
- package/src/hash.ts +10 -0
- package/src/index.ts +14 -0
- package/src/key.ts +80 -0
- package/src/keychain.ts +197 -0
- package/src/libp2p.ts +27 -0
- package/src/prehash.ts +42 -0
- package/src/random-browser.ts +2 -0
- package/src/random.ts +2 -0
- package/src/sepc256k1.ts +229 -0
- package/src/signature.ts +284 -0
- package/src/signer.ts +18 -0
- package/src/utils.ts +15 -0
- package/src/x25519.ts +167 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { keysPBM } from "@libp2p/crypto/keys";
|
|
2
|
+
import { identity } from "multiformats/hashes/identity";
|
|
3
|
+
import { base58btc } from "multiformats/bases/base58";
|
|
4
|
+
import { Ed25519Keypair, Ed25519PublicKey } from "./ed25519.js";
|
|
5
|
+
import { Keypair, PublicSignKey } from "./key.js";
|
|
6
|
+
import { AccessError, X25519Keypair, X25519PublicKey } from "./x25519.js";
|
|
7
|
+
export class Libp2pKeychain {
|
|
8
|
+
keychain;
|
|
9
|
+
options;
|
|
10
|
+
constructor(keychain, options) {
|
|
11
|
+
this.keychain = keychain;
|
|
12
|
+
this.options = options;
|
|
13
|
+
}
|
|
14
|
+
keychainKeyIdFromPublicKey(publicKey) {
|
|
15
|
+
const bytes = keysPBM.PublicKey.encode({
|
|
16
|
+
Type: keysPBM.KeyType.Ed25519,
|
|
17
|
+
Data: publicKey.publicKey,
|
|
18
|
+
}).subarray();
|
|
19
|
+
const encoding = identity.digest(bytes);
|
|
20
|
+
return base58btc.encode(encoding.bytes).substring(1);
|
|
21
|
+
}
|
|
22
|
+
cacheKey(key, id) {
|
|
23
|
+
this.options?.cache?.add(base58btc.encode(key.publicKey.bytes), key);
|
|
24
|
+
id && this.options?.cache?.add(base58btc.encode(id), key);
|
|
25
|
+
}
|
|
26
|
+
getCachedById(id) {
|
|
27
|
+
const key = base58btc.encode(id instanceof PublicSignKey ? id.bytes : id);
|
|
28
|
+
const cached = this.options?.cache?.get(key);
|
|
29
|
+
if (cached === null) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
else if (!cached) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
else if (cached instanceof Ed25519Keypair) {
|
|
36
|
+
return cached;
|
|
37
|
+
}
|
|
38
|
+
throw new Error("Unexpected cached keypair type: " + key?.constructor.name);
|
|
39
|
+
}
|
|
40
|
+
getCachedByKey(publicKey) {
|
|
41
|
+
const key = base58btc.encode(publicKey.bytes);
|
|
42
|
+
const cached = this.options?.cache?.get(key);
|
|
43
|
+
if (cached === null) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
else if (!cached) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
else if (cached instanceof Keypair) {
|
|
50
|
+
return cached;
|
|
51
|
+
}
|
|
52
|
+
throw new Error("Unexpected cached keypair type: " + key?.constructor.name);
|
|
53
|
+
}
|
|
54
|
+
exportByKey = async (publicKey) => {
|
|
55
|
+
const cached = this.getCachedByKey(publicKey);
|
|
56
|
+
if (cached !== undefined) {
|
|
57
|
+
// if null, means key is deleted
|
|
58
|
+
return cached ? cached : undefined;
|
|
59
|
+
}
|
|
60
|
+
let keyInfo = undefined;
|
|
61
|
+
if (publicKey instanceof Ed25519PublicKey) {
|
|
62
|
+
try {
|
|
63
|
+
keyInfo = await this.keychain.findKeyById((await publicKey.toPeerId()).toString());
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
if (e.code !== "ERR_KEY_NOT_FOUND") {
|
|
67
|
+
throw e;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
keyInfo = await this.keychain.findKeyByName(base58btc.encode(publicKey.bytes));
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
if (e.code !== "ERR_KEY_NOT_FOUND") {
|
|
76
|
+
throw e;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!keyInfo) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
const peerId = await this.keychain.exportPeerId(keyInfo.name);
|
|
83
|
+
return (publicKey instanceof X25519PublicKey
|
|
84
|
+
? X25519Keypair.fromPeerId(peerId)
|
|
85
|
+
: Ed25519Keypair.fromPeerId(peerId));
|
|
86
|
+
};
|
|
87
|
+
async exportById(id, type) {
|
|
88
|
+
const cached = this.getCachedById(id);
|
|
89
|
+
if (cached !== undefined) {
|
|
90
|
+
// if null, means key is deleted
|
|
91
|
+
if (type === "x25519" && cached instanceof Ed25519Keypair) {
|
|
92
|
+
return X25519Keypair.from(cached); // TODO perf, don't do this all the time
|
|
93
|
+
}
|
|
94
|
+
return cached ? cached : undefined;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const keyInfo = await this.keychain.findKeyByName(base58btc.encode(id));
|
|
98
|
+
const peerId = await this.keychain.exportPeerId(keyInfo.name);
|
|
99
|
+
if (type === "x25519") {
|
|
100
|
+
return X25519Keypair.fromPeerId(peerId);
|
|
101
|
+
}
|
|
102
|
+
return Ed25519Keypair.fromPeerId(peerId);
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
if (e.code !== "ERR_KEY_NOT_FOUND") {
|
|
106
|
+
throw e;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
import = async (keypair, id) => {
|
|
111
|
+
const receiverKeyPeerId = await keypair.toPeerId();
|
|
112
|
+
this.cacheKey(keypair, id);
|
|
113
|
+
// import as ed
|
|
114
|
+
await this.keychain.importPeer(base58btc.encode(id), receiverKeyPeerId);
|
|
115
|
+
// import as x so we can decrypt messages with this public key (if recieved any)
|
|
116
|
+
const xKeypair = await X25519Keypair.from(keypair);
|
|
117
|
+
this.cacheKey(xKeypair);
|
|
118
|
+
await this.keychain.importPeer(base58btc.encode(xKeypair.publicKey.bytes), receiverKeyPeerId);
|
|
119
|
+
};
|
|
120
|
+
// Arrow function is used so we can reference this function and use 'this' without .bind(self)
|
|
121
|
+
getAnyKeypair = async (publicKeys) => {
|
|
122
|
+
for (let i = 0; i < publicKeys.length; i++) {
|
|
123
|
+
try {
|
|
124
|
+
const key = await this.exportByKey(publicKeys[i]);
|
|
125
|
+
if (key && key instanceof X25519Keypair) {
|
|
126
|
+
return {
|
|
127
|
+
index: i,
|
|
128
|
+
keypair: key,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
// Key missing
|
|
134
|
+
if (error.code !== "ERR_NOT_FOUND") {
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
throw new AccessError("Failed to access key");
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=keychain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keychain.js","sourceRoot":"","sources":["../../src/keychain.ts"],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F,aAAa,GAAG,KAAK,EAAE,UAAU,EAAE,EAAE;QACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC3C,IAAI;gBACH,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClD,IAAI,GAAG,IAAI,GAAG,YAAY,aAAa,EAAE;oBACxC,OAAO;wBACN,KAAK,EAAE,CAAC;wBACR,OAAO,EAAE,GAAoB;qBAC7B,CAAC;iBACF;aACD;YAAC,OAAO,KAAU,EAAE;gBACpB,cAAc;gBACd,IAAI,KAAK,CAAC,IAAI,KAAK,eAAe,EAAE;oBACnC,MAAM,KAAK,CAAC;iBACZ;aACD;SACD;QACD,MAAM,IAAI,WAAW,CAAC,sBAAsB,CAAC,CAAC;IAC/C,CAAC,CAAC;CACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PeerId } from "@libp2p/interface-peer-id";
|
|
2
|
+
import { Ed25519Keypair, Ed25519PublicKey } from "./ed25519.js";
|
|
3
|
+
import { Secp256k1Keypair, Secp256k1PublicKey } from "./sepc256k1.js";
|
|
4
|
+
export declare const getKeypairFromPeerId: (peerId: PeerId) => Ed25519Keypair | Secp256k1Keypair;
|
|
5
|
+
export declare const getPublicKeyFromPeerId: (peerId: PeerId) => Ed25519PublicKey | Secp256k1PublicKey;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Ed25519Keypair, Ed25519PublicKey } from "./ed25519.js";
|
|
2
|
+
import { Secp256k1Keypair, Secp256k1PublicKey } from "./sepc256k1.js";
|
|
3
|
+
export const getKeypairFromPeerId = (peerId) => {
|
|
4
|
+
if (peerId.type === "Ed25519") {
|
|
5
|
+
return Ed25519Keypair.fromPeerId(peerId);
|
|
6
|
+
}
|
|
7
|
+
if (peerId.type === "secp256k1") {
|
|
8
|
+
return Secp256k1Keypair.fromPeerId(peerId);
|
|
9
|
+
}
|
|
10
|
+
throw new Error("Unsupported key type");
|
|
11
|
+
};
|
|
12
|
+
export const getPublicKeyFromPeerId = (peerId) => {
|
|
13
|
+
if (peerId.type === "Ed25519") {
|
|
14
|
+
return Ed25519PublicKey.fromPeerId(peerId);
|
|
15
|
+
}
|
|
16
|
+
if (peerId.type === "secp256k1") {
|
|
17
|
+
return Secp256k1PublicKey.from(peerId);
|
|
18
|
+
}
|
|
19
|
+
throw new Error("Unsupported key type");
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=libp2p.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libp2p.js","sourceRoot":"","sources":["../../src/libp2p.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEtE,MAAM,CAAC,MAAM,oBAAoB,GAAG,CACnC,MAAc,EACsB,EAAE;IACtC,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE;QAC9B,OAAO,cAAc,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;KACzC;IACD,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE;QAChC,OAAO,gBAAgB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;KAC3C;IACD,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;AACzC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACrC,MAAc,EAC0B,EAAE;IAC1C,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE;QAC9B,OAAO,gBAAgB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;KAC3C;IACD,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE;QAChC,OAAO,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;KACvC;IACD,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;AACzC,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { sha256 } from "./hash.js";
|
|
2
|
+
import sha3 from "js-sha3";
|
|
3
|
+
import { toUtf8Bytes } from "@ethersproject/strings";
|
|
4
|
+
import { concat } from "uint8arrays";
|
|
5
|
+
const messagePrefix = "\x19Ethereum Signed Message:\n";
|
|
6
|
+
const ethKeccak256Hash = (message) => new Uint8Array(sha3.keccak256
|
|
7
|
+
.update(concat([
|
|
8
|
+
toUtf8Bytes(messagePrefix),
|
|
9
|
+
toUtf8Bytes(String(message.length)),
|
|
10
|
+
message,
|
|
11
|
+
]))
|
|
12
|
+
.arrayBuffer());
|
|
13
|
+
export var PreHash;
|
|
14
|
+
(function (PreHash) {
|
|
15
|
+
PreHash[PreHash["NONE"] = 0] = "NONE";
|
|
16
|
+
PreHash[PreHash["SHA_256"] = 1] = "SHA_256";
|
|
17
|
+
//BLAKE3 = 2,
|
|
18
|
+
PreHash[PreHash["ETH_KECCAK_256"] = 3] = "ETH_KECCAK_256";
|
|
19
|
+
})(PreHash || (PreHash = {}));
|
|
20
|
+
export const prehashFn = (data, prehash) => {
|
|
21
|
+
if (prehash === PreHash.NONE) {
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
if (prehash === PreHash.SHA_256) {
|
|
25
|
+
return sha256(data);
|
|
26
|
+
}
|
|
27
|
+
if (prehash === PreHash.ETH_KECCAK_256) {
|
|
28
|
+
return ethKeccak256Hash(data);
|
|
29
|
+
}
|
|
30
|
+
throw new Error("Unsupported");
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=prehash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prehash.js","sourceRoot":"","sources":["../../src/prehash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,aAAa,GAAG,gCAAgC,CAAC;AACvD,MAAM,gBAAgB,GAAG,CAAC,OAAmB,EAAE,EAAE,CAChD,IAAI,UAAU,CACb,IAAI,CAAC,SAAS;KACZ,MAAM,CACN,MAAM,CAAC;IACN,WAAW,CAAC,aAAa,CAAC;IAC1B,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACnC,OAAO;CACP,CAAC,CACF;KACA,WAAW,EAAE,CACf,CAAC;AAEH,MAAM,CAAN,IAAY,OAKX;AALD,WAAY,OAAO;IAClB,qCAAQ,CAAA;IACR,2CAAW,CAAA;IACX,aAAa;IACb,yDAAkB,CAAA;AACnB,CAAC,EALW,OAAO,KAAP,OAAO,QAKlB;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CACxB,IAAgB,EAChB,OAAgB,EACmB,EAAE;IACrC,IAAI,OAAO,KAAK,OAAO,CAAC,IAAI,EAAE;QAC7B,OAAO,IAAI,CAAC;KACZ;IACD,IAAI,OAAO,KAAK,OAAO,CAAC,OAAO,EAAE;QAChC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;KACpB;IACD,IAAI,OAAO,KAAK,OAAO,CAAC,cAAc,EAAE;QACvC,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC;KAC9B;IAED,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;AAChC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const randomBytes: (len: number) => Uint8Array;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random-browser.js","sourceRoot":"","sources":["../../src/random-browser.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAW,EAAE,EAAE,CAC1C,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.js","sourceRoot":"","sources":["../../src/random.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Keypair, PrivateSignKey, PublicSignKey } from "./key.js";
|
|
2
|
+
import { Wallet } from "@ethersproject/wallet";
|
|
3
|
+
import { SignatureLike } from "@ethersproject/bytes";
|
|
4
|
+
import { PeerId } from "@libp2p/interface-peer-id";
|
|
5
|
+
import { Identity } from "./signer.js";
|
|
6
|
+
import { SignatureWithKey } from "./signature.js";
|
|
7
|
+
import { PreHash } from "./prehash.js";
|
|
8
|
+
export declare class Secp256k1PublicKey extends PublicSignKey {
|
|
9
|
+
publicKey: Uint8Array;
|
|
10
|
+
constructor(properties: {
|
|
11
|
+
publicKey: Uint8Array;
|
|
12
|
+
});
|
|
13
|
+
static recover(wallet: Wallet): Promise<Secp256k1PublicKey>;
|
|
14
|
+
equals(other: PublicSignKey): boolean;
|
|
15
|
+
toString(): string;
|
|
16
|
+
static from(id: PeerId): Secp256k1PublicKey;
|
|
17
|
+
}
|
|
18
|
+
export declare class Secp256k1PrivateKey extends PrivateSignKey {
|
|
19
|
+
privateKey: Uint8Array;
|
|
20
|
+
constructor(properties: {
|
|
21
|
+
privateKey: Uint8Array;
|
|
22
|
+
});
|
|
23
|
+
equals(other: Secp256k1PrivateKey): boolean;
|
|
24
|
+
toString(): string;
|
|
25
|
+
static from(id: PeerId): Secp256k1PrivateKey;
|
|
26
|
+
}
|
|
27
|
+
export declare class Secp256k1Keypair extends Keypair implements Identity {
|
|
28
|
+
publicKey: Secp256k1PublicKey;
|
|
29
|
+
privateKey: Secp256k1PrivateKey;
|
|
30
|
+
_wallet: Wallet;
|
|
31
|
+
constructor(properties: {
|
|
32
|
+
publicKey: Secp256k1PublicKey;
|
|
33
|
+
privateKey: Secp256k1PrivateKey;
|
|
34
|
+
});
|
|
35
|
+
static create(): Promise<Secp256k1Keypair>;
|
|
36
|
+
sign(data: Uint8Array, prehash?: PreHash): Promise<SignatureWithKey>;
|
|
37
|
+
equals(other: Keypair): boolean;
|
|
38
|
+
static fromPeerId(peerId: PeerId): Secp256k1Keypair;
|
|
39
|
+
toPeerId(): Promise<PeerId>;
|
|
40
|
+
}
|
|
41
|
+
export declare const recoverPublicKeyFromSignature: (digest: Uint8Array, signature: SignatureLike) => Uint8Array;
|
|
42
|
+
export declare const verifySignatureSecp256k1: (signature: SignatureWithKey, data: Uint8Array) => Promise<boolean>;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var Secp256k1PublicKey_1, Secp256k1PrivateKey_1, Secp256k1Keypair_1;
|
|
11
|
+
import { field, fixedArray, variant } from "@dao-xyz/borsh";
|
|
12
|
+
import { Keypair, PrivateSignKey, PublicSignKey } from "./key.js";
|
|
13
|
+
import { Wallet } from "@ethersproject/wallet";
|
|
14
|
+
import { arrayify } from "@ethersproject/bytes";
|
|
15
|
+
import { joinSignature } from "@ethersproject/bytes";
|
|
16
|
+
import { splitSignature } from "@ethersproject/bytes";
|
|
17
|
+
import _ec from "elliptic";
|
|
18
|
+
var EC = _ec.ec;
|
|
19
|
+
let _curve;
|
|
20
|
+
import { equals } from "@peerbit/uint8arrays";
|
|
21
|
+
import { toHexString } from "./utils.js";
|
|
22
|
+
import { coerce } from "./bytes.js";
|
|
23
|
+
import { generateKeyPair, supportedKeys } from "@libp2p/crypto/keys";
|
|
24
|
+
import utf8 from "@protobufjs/utf8";
|
|
25
|
+
import { SignatureWithKey } from "./signature.js";
|
|
26
|
+
import { PreHash, prehashFn } from "./prehash.js";
|
|
27
|
+
import { peerIdFromKeys } from "@libp2p/peer-id";
|
|
28
|
+
export let Secp256k1PublicKey = Secp256k1PublicKey_1 = class Secp256k1PublicKey extends PublicSignKey {
|
|
29
|
+
publicKey;
|
|
30
|
+
constructor(properties) {
|
|
31
|
+
super();
|
|
32
|
+
if (properties.publicKey.length !== 33) {
|
|
33
|
+
throw new Error("Expecting key to have length 33");
|
|
34
|
+
}
|
|
35
|
+
this.publicKey = properties.publicKey;
|
|
36
|
+
}
|
|
37
|
+
static async recover(wallet) {
|
|
38
|
+
// Signa message
|
|
39
|
+
const toSign = new Uint8Array([0]);
|
|
40
|
+
const signature = await wallet.signMessage(toSign);
|
|
41
|
+
// So we can recover the public key
|
|
42
|
+
const publicKey = recoverPublicKeyFromSignature(await prehashFn(toSign, PreHash.ETH_KECCAK_256), signature);
|
|
43
|
+
return new Secp256k1PublicKey_1({ publicKey });
|
|
44
|
+
}
|
|
45
|
+
equals(other) {
|
|
46
|
+
if (other instanceof Secp256k1PublicKey_1) {
|
|
47
|
+
return equals(this.publicKey, other.publicKey);
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
toString() {
|
|
52
|
+
return "sepc256k1/" + toHexString(this.publicKey);
|
|
53
|
+
}
|
|
54
|
+
static from(id) {
|
|
55
|
+
if (!id.publicKey) {
|
|
56
|
+
throw new Error("Missing public key");
|
|
57
|
+
}
|
|
58
|
+
if (id.type === "secp256k1") {
|
|
59
|
+
return new Secp256k1PublicKey_1({
|
|
60
|
+
publicKey: id.publicKey.slice(4), // computeAddress(!.slice(4)),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
throw new Error("Unsupported key type: " + id.type);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
__decorate([
|
|
67
|
+
field({ type: fixedArray("u8", 33) }),
|
|
68
|
+
__metadata("design:type", Uint8Array)
|
|
69
|
+
], Secp256k1PublicKey.prototype, "publicKey", void 0);
|
|
70
|
+
Secp256k1PublicKey = Secp256k1PublicKey_1 = __decorate([
|
|
71
|
+
variant(1),
|
|
72
|
+
__metadata("design:paramtypes", [Object])
|
|
73
|
+
], Secp256k1PublicKey);
|
|
74
|
+
export let Secp256k1PrivateKey = Secp256k1PrivateKey_1 = class Secp256k1PrivateKey extends PrivateSignKey {
|
|
75
|
+
privateKey;
|
|
76
|
+
constructor(properties) {
|
|
77
|
+
super();
|
|
78
|
+
if (properties.privateKey.length !== 32) {
|
|
79
|
+
throw new Error("Expecting key to have length 32");
|
|
80
|
+
}
|
|
81
|
+
this.privateKey = properties.privateKey;
|
|
82
|
+
}
|
|
83
|
+
equals(other) {
|
|
84
|
+
if (other instanceof Secp256k1PrivateKey_1) {
|
|
85
|
+
return equals(this.privateKey, other.privateKey);
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
toString() {
|
|
90
|
+
return "secp256k1s/" + toHexString(this.privateKey);
|
|
91
|
+
}
|
|
92
|
+
static from(id) {
|
|
93
|
+
if (!id.privateKey) {
|
|
94
|
+
throw new Error("Missing privateKey key");
|
|
95
|
+
}
|
|
96
|
+
if (id.type === "secp256k1") {
|
|
97
|
+
return new Secp256k1PrivateKey_1({
|
|
98
|
+
privateKey: coerce(id.privateKey.slice(4)),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
throw new Error("Unsupported key type: " + id.type);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
__decorate([
|
|
105
|
+
field({ type: Uint8Array }),
|
|
106
|
+
__metadata("design:type", Uint8Array)
|
|
107
|
+
], Secp256k1PrivateKey.prototype, "privateKey", void 0);
|
|
108
|
+
Secp256k1PrivateKey = Secp256k1PrivateKey_1 = __decorate([
|
|
109
|
+
variant(1),
|
|
110
|
+
__metadata("design:paramtypes", [Object])
|
|
111
|
+
], Secp256k1PrivateKey);
|
|
112
|
+
export let Secp256k1Keypair = Secp256k1Keypair_1 = class Secp256k1Keypair extends Keypair {
|
|
113
|
+
publicKey;
|
|
114
|
+
privateKey;
|
|
115
|
+
_wallet;
|
|
116
|
+
constructor(properties) {
|
|
117
|
+
super();
|
|
118
|
+
this.privateKey = properties.privateKey;
|
|
119
|
+
this.publicKey = properties.publicKey;
|
|
120
|
+
}
|
|
121
|
+
static async create() {
|
|
122
|
+
const generated = await generateKeyPair("secp256k1");
|
|
123
|
+
const kp = new Secp256k1Keypair_1({
|
|
124
|
+
publicKey: new Secp256k1PublicKey({
|
|
125
|
+
publicKey: generated.public.marshal(),
|
|
126
|
+
}),
|
|
127
|
+
privateKey: new Secp256k1PrivateKey({
|
|
128
|
+
privateKey: generated.marshal(),
|
|
129
|
+
}),
|
|
130
|
+
});
|
|
131
|
+
return kp;
|
|
132
|
+
}
|
|
133
|
+
async sign(data, prehash = PreHash.ETH_KECCAK_256) {
|
|
134
|
+
const maybeHashed = await prehashFn(data, prehash);
|
|
135
|
+
const signature = joinSignature((this._wallet || (this._wallet = new Wallet(this.privateKey.privateKey)))
|
|
136
|
+
._signingKey()
|
|
137
|
+
.signDigest(maybeHashed));
|
|
138
|
+
const signatureBytes = new Uint8Array(utf8.length(signature)); // TODO utilize Buffer allocUnsafe
|
|
139
|
+
utf8.write(signature, signatureBytes, 0);
|
|
140
|
+
return new SignatureWithKey({
|
|
141
|
+
prehash,
|
|
142
|
+
publicKey: this.publicKey,
|
|
143
|
+
signature: signatureBytes,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
equals(other) {
|
|
147
|
+
if (other instanceof Secp256k1Keypair_1) {
|
|
148
|
+
return (this.publicKey.equals(other.publicKey) &&
|
|
149
|
+
this.privateKey.equals(other.privateKey));
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
static fromPeerId(peerId) {
|
|
154
|
+
return new Secp256k1Keypair_1({
|
|
155
|
+
privateKey: Secp256k1PrivateKey.from(peerId),
|
|
156
|
+
publicKey: Secp256k1PublicKey.from(peerId),
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
toPeerId() {
|
|
160
|
+
return peerIdFromKeys(new supportedKeys["secp256k1"].Secp256k1PublicKey(this.publicKey.publicKey).bytes, new supportedKeys["secp256k1"].Secp256k1PrivateKey(this.privateKey.privateKey, this.publicKey.publicKey).bytes);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
__decorate([
|
|
164
|
+
field({ type: Secp256k1PublicKey }),
|
|
165
|
+
__metadata("design:type", Secp256k1PublicKey)
|
|
166
|
+
], Secp256k1Keypair.prototype, "publicKey", void 0);
|
|
167
|
+
__decorate([
|
|
168
|
+
field({ type: Secp256k1PrivateKey }),
|
|
169
|
+
__metadata("design:type", Secp256k1PrivateKey)
|
|
170
|
+
], Secp256k1Keypair.prototype, "privateKey", void 0);
|
|
171
|
+
Secp256k1Keypair = Secp256k1Keypair_1 = __decorate([
|
|
172
|
+
variant(2),
|
|
173
|
+
__metadata("design:paramtypes", [Object])
|
|
174
|
+
], Secp256k1Keypair);
|
|
175
|
+
const decoder = new TextDecoder();
|
|
176
|
+
function getCurve() {
|
|
177
|
+
if (!_curve) {
|
|
178
|
+
_curve = new EC("secp256k1");
|
|
179
|
+
}
|
|
180
|
+
return _curve;
|
|
181
|
+
}
|
|
182
|
+
export const recoverPublicKeyFromSignature = (digest, signature) => {
|
|
183
|
+
const sig = splitSignature(signature);
|
|
184
|
+
const rs = { r: arrayify(sig.r), s: arrayify(sig.s) };
|
|
185
|
+
return new Uint8Array(getCurve()
|
|
186
|
+
.recoverPubKey(arrayify(digest), rs, sig.recoveryParam)
|
|
187
|
+
.encodeCompressed());
|
|
188
|
+
};
|
|
189
|
+
export const verifySignatureSecp256k1 = async (signature, data) => {
|
|
190
|
+
const hashedData = await prehashFn(data, signature.prehash);
|
|
191
|
+
const signerKey = recoverPublicKeyFromSignature(arrayify(hashedData), decoder.decode(signature.signature));
|
|
192
|
+
return equals(signerKey, signature.publicKey.publicKey);
|
|
193
|
+
};
|
|
194
|
+
//# sourceMappingURL=sepc256k1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sepc256k1.js","sourceRoot":"","sources":["../../src/sepc256k1.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAO,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAiB,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,IAAO,EAAE,GAAG,GAAG,CAAC,EAAE,CAAC;AACnB,IAAI,MAAU,CAAC;AAEf,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,aA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BAA6B,CAC9C,QAAQ,CAAC,UAAU,CAAC,EACpB,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CACnC,CAAC;IACF,OAAO,MAAM,CACZ,SAAS,EACR,SAAS,CAAC,SAAgC,CAAC,SAAS,CACrD,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AbstractType } from "@dao-xyz/borsh";
|
|
2
|
+
import { PublicSignKey } from "./key.js";
|
|
3
|
+
import { PreHash } from "./prehash.js";
|
|
4
|
+
import { SignWithKey } from "./signer.js";
|
|
5
|
+
export declare class SignatureWithKey {
|
|
6
|
+
signature: Uint8Array;
|
|
7
|
+
publicKey: PublicSignKey;
|
|
8
|
+
prehash: PreHash;
|
|
9
|
+
constructor(props: {
|
|
10
|
+
signature: Uint8Array;
|
|
11
|
+
publicKey: PublicSignKey;
|
|
12
|
+
prehash: PreHash;
|
|
13
|
+
});
|
|
14
|
+
equals(other: SignatureWithKey): boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare class MaybeSigned<T> {
|
|
17
|
+
data: Uint8Array;
|
|
18
|
+
signature?: SignatureWithKey;
|
|
19
|
+
constructor(props?: {
|
|
20
|
+
data: Uint8Array;
|
|
21
|
+
value?: T;
|
|
22
|
+
signature?: SignatureWithKey;
|
|
23
|
+
});
|
|
24
|
+
_value?: T;
|
|
25
|
+
getValue(constructor: AbstractType<T>): T;
|
|
26
|
+
verify(): Promise<boolean>;
|
|
27
|
+
equals(other: MaybeSigned<T>): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* In place
|
|
30
|
+
* @param signer
|
|
31
|
+
*/
|
|
32
|
+
sign(signer: SignWithKey): Promise<MaybeSigned<T>>;
|
|
33
|
+
}
|
|
34
|
+
export declare const verify: (signature: SignatureWithKey, data: Uint8Array) => Promise<boolean>;
|