@peerbit/crypto 2.3.13-d375893 → 2.4.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/LICENSE +202 -0
- package/dist/benchmark/hash.js +68 -27
- package/dist/benchmark/hash.js.map +1 -1
- package/dist/src/bytes.d.ts.map +1 -1
- package/dist/src/bytes.js +4 -2
- package/dist/src/bytes.js.map +1 -1
- package/dist/src/ed25519.js +209 -144
- package/dist/src/ed25519.js.map +1 -1
- package/dist/src/encryption.d.ts.map +1 -1
- package/dist/src/encryption.js +417 -295
- package/dist/src/encryption.js.map +1 -1
- package/dist/src/key.js +60 -25
- package/dist/src/key.js.map +1 -1
- package/dist/src/random.d.ts +1 -1
- package/dist/src/random.d.ts.map +1 -1
- package/dist/src/sepc256k1.js +202 -136
- package/dist/src/sepc256k1.js.map +1 -1
- package/dist/src/signature.js +139 -86
- package/dist/src/signature.js.map +1 -1
- package/dist/src/x25519.js +208 -141
- package/dist/src/x25519.js.map +1 -1
- package/package.json +12 -12
- package/src/bytes.ts +6 -2
- package/src/encryption.ts +3 -1
package/dist/src/signature.js
CHANGED
|
@@ -1,11 +1,36 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
6
27
|
};
|
|
7
|
-
var
|
|
8
|
-
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
9
34
|
};
|
|
10
35
|
import { deserialize, field, option, serialize, variant, } from "@dao-xyz/borsh";
|
|
11
36
|
import { compare, equals } from "uint8arrays";
|
|
@@ -15,91 +40,119 @@ import { PublicSignKey } from "./key.js";
|
|
|
15
40
|
import { PreHash } from "./prehash.js";
|
|
16
41
|
import { Secp256k1PublicKey, verifySignatureSecp256k1 } from "./sepc256k1.js";
|
|
17
42
|
import {} from "./signer.js";
|
|
18
|
-
let SignatureWithKey =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
43
|
+
let SignatureWithKey = (() => {
|
|
44
|
+
let _classDecorators = [variant(0)];
|
|
45
|
+
let _classDescriptor;
|
|
46
|
+
let _classExtraInitializers = [];
|
|
47
|
+
let _classThis;
|
|
48
|
+
let _signature_decorators;
|
|
49
|
+
let _signature_initializers = [];
|
|
50
|
+
let _signature_extraInitializers = [];
|
|
51
|
+
let _publicKey_decorators;
|
|
52
|
+
let _publicKey_initializers = [];
|
|
53
|
+
let _publicKey_extraInitializers = [];
|
|
54
|
+
let _prehash_decorators;
|
|
55
|
+
let _prehash_initializers = [];
|
|
56
|
+
let _prehash_extraInitializers = [];
|
|
57
|
+
var SignatureWithKey = class {
|
|
58
|
+
static { _classThis = this; }
|
|
59
|
+
static {
|
|
60
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
61
|
+
_signature_decorators = [field({ type: Uint8Array })];
|
|
62
|
+
_publicKey_decorators = [field({ type: PublicSignKey })];
|
|
63
|
+
_prehash_decorators = [field({ type: "u8" })];
|
|
64
|
+
__esDecorate(null, null, _signature_decorators, { kind: "field", name: "signature", static: false, private: false, access: { has: obj => "signature" in obj, get: obj => obj.signature, set: (obj, value) => { obj.signature = value; } }, metadata: _metadata }, _signature_initializers, _signature_extraInitializers);
|
|
65
|
+
__esDecorate(null, null, _publicKey_decorators, { kind: "field", name: "publicKey", static: false, private: false, access: { has: obj => "publicKey" in obj, get: obj => obj.publicKey, set: (obj, value) => { obj.publicKey = value; } }, metadata: _metadata }, _publicKey_initializers, _publicKey_extraInitializers);
|
|
66
|
+
__esDecorate(null, null, _prehash_decorators, { kind: "field", name: "prehash", static: false, private: false, access: { has: obj => "prehash" in obj, get: obj => obj.prehash, set: (obj, value) => { obj.prehash = value; } }, metadata: _metadata }, _prehash_initializers, _prehash_extraInitializers);
|
|
67
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
68
|
+
SignatureWithKey = _classThis = _classDescriptor.value;
|
|
69
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
70
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
30
71
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
], SignatureWithKey);
|
|
72
|
+
signature = __runInitializers(this, _signature_initializers, void 0);
|
|
73
|
+
publicKey = (__runInitializers(this, _signature_extraInitializers), __runInitializers(this, _publicKey_initializers, void 0));
|
|
74
|
+
prehash = (__runInitializers(this, _publicKey_extraInitializers), __runInitializers(this, _prehash_initializers, PreHash.NONE)); // 0 no prehash, 1 sha256, 2 blake3?
|
|
75
|
+
constructor(props) {
|
|
76
|
+
__runInitializers(this, _prehash_extraInitializers);
|
|
77
|
+
this.signature = props.signature;
|
|
78
|
+
this.publicKey = props.publicKey;
|
|
79
|
+
this.prehash = props.prehash;
|
|
80
|
+
}
|
|
81
|
+
equals(other) {
|
|
82
|
+
if (!equals(this.signature, other.signature)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return (compare(serialize(this.publicKey), serialize(other.publicKey)) === 0 &&
|
|
86
|
+
this.prehash === other.prehash);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
return SignatureWithKey = _classThis;
|
|
90
|
+
})();
|
|
51
91
|
export { SignatureWithKey };
|
|
52
|
-
let MaybeSigned =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
92
|
+
let MaybeSigned = (() => {
|
|
93
|
+
let _classDecorators = [variant(0)];
|
|
94
|
+
let _classDescriptor;
|
|
95
|
+
let _classExtraInitializers = [];
|
|
96
|
+
let _classThis;
|
|
97
|
+
let _data_decorators;
|
|
98
|
+
let _data_initializers = [];
|
|
99
|
+
let _data_extraInitializers = [];
|
|
100
|
+
let _signature_decorators;
|
|
101
|
+
let _signature_initializers = [];
|
|
102
|
+
let _signature_extraInitializers = [];
|
|
103
|
+
var MaybeSigned = class {
|
|
104
|
+
static { _classThis = this; }
|
|
105
|
+
static {
|
|
106
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
107
|
+
_data_decorators = [field({ type: Uint8Array })];
|
|
108
|
+
_signature_decorators = [field({ type: option(SignatureWithKey) })];
|
|
109
|
+
__esDecorate(null, null, _data_decorators, { kind: "field", name: "data", static: false, private: false, access: { has: obj => "data" in obj, get: obj => obj.data, set: (obj, value) => { obj.data = value; } }, metadata: _metadata }, _data_initializers, _data_extraInitializers);
|
|
110
|
+
__esDecorate(null, null, _signature_decorators, { kind: "field", name: "signature", static: false, private: false, access: { has: obj => "signature" in obj, get: obj => obj.signature, set: (obj, value) => { obj.signature = value; } }, metadata: _metadata }, _signature_initializers, _signature_extraInitializers);
|
|
111
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
112
|
+
MaybeSigned = _classThis = _classDescriptor.value;
|
|
113
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
114
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
67
115
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
116
|
+
data = __runInitializers(this, _data_initializers, void 0);
|
|
117
|
+
signature = (__runInitializers(this, _data_extraInitializers), __runInitializers(this, _signature_initializers, void 0));
|
|
118
|
+
constructor(props) {
|
|
119
|
+
this.data = props.data;
|
|
120
|
+
this.signature = props.signature;
|
|
121
|
+
this._value = props.value;
|
|
73
122
|
}
|
|
74
|
-
|
|
75
|
-
|
|
123
|
+
_value = __runInitializers(this, _signature_extraInitializers);
|
|
124
|
+
getValue(constructor) {
|
|
125
|
+
return deserialize(this.data, constructor);
|
|
76
126
|
}
|
|
77
|
-
|
|
78
|
-
|
|
127
|
+
async verify() {
|
|
128
|
+
if (!this.signature) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
return verify(this.signature, this.data);
|
|
79
132
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
133
|
+
equals(other) {
|
|
134
|
+
if (!equals(this.data, other.data)) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
if (!this.signature !== !other.signature) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
if (this.signature && other.signature) {
|
|
141
|
+
return this.signature.equals(other.signature);
|
|
142
|
+
}
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
/*
|
|
146
|
+
In place signing
|
|
147
|
+
*/
|
|
148
|
+
async sign(signer) {
|
|
149
|
+
const signatureResult = await signer(this.data);
|
|
150
|
+
this.signature = signatureResult;
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
return MaybeSigned = _classThis;
|
|
155
|
+
})();
|
|
103
156
|
export { MaybeSigned };
|
|
104
157
|
export const verify = async (signature, data) => {
|
|
105
158
|
if (signature.publicKey instanceof Ed25519PublicKey) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signature.js","sourceRoot":"","sources":["../../src/signature.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signature.js","sourceRoot":"","sources":["../../src/signature.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAEN,WAAW,EACX,KAAK,EACL,MAAM,EACN,SAAS,EACT,OAAO,GACP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAoB,MAAM,aAAa,CAAC;IAGlC,gBAAgB;4BAD5B,OAAO,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;qCAET,KAAK,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;qCAG3B,KAAK,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;mCAG9B,KAAK,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;YALtB,6KAAA,SAAS,6BAAT,SAAS,6FAAa;YAGtB,6KAAA,SAAS,6BAAT,SAAS,6FAAgB;YAGzB,uKAAA,OAAO,6BAAP,OAAO,yFAAyB;YARjC,6KA6BC;;;YA7BY,uDAAgB;;QA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