@virtonetwork/authenticators-substrate 1.0.0 → 1.1.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/dist/cjs/index.js +22 -11
- package/dist/cjs/types.js +14 -3
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +10 -3
- package/dist/esm/types.d.ts +20 -4
- package/dist/esm/types.js +14 -3
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -36,9 +36,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.SubstrateKey = exports.KREIVO_AUTHORITY_ID = void 0;
|
|
39
|
+
exports.SubstrateKey = exports.KREIVO_AUTHORITY_ID = exports.KeyRegistration = exports.KeySignature = exports.SignedMessage = void 0;
|
|
40
40
|
var signer_1 = require("@virtonetwork/signer");
|
|
41
41
|
var types_ts_1 = require("./types.js");
|
|
42
|
+
Object.defineProperty(exports, "KeyRegistration", { enumerable: true, get: function () { return types_ts_1.KeyRegistration; } });
|
|
43
|
+
Object.defineProperty(exports, "KeySignature", { enumerable: true, get: function () { return types_ts_1.KeySignature; } });
|
|
44
|
+
Object.defineProperty(exports, "SignedMessage", { enumerable: true, get: function () { return types_ts_1.SignedMessage; } });
|
|
42
45
|
var polkadot_api_1 = require("polkadot-api");
|
|
43
46
|
exports.KREIVO_AUTHORITY_ID = polkadot_api_1.Binary.fromText("kreivo_p".padEnd(32, "\0"));
|
|
44
47
|
var SubstrateKey = /** @class */ (function () {
|
|
@@ -91,12 +94,12 @@ var SubstrateKey = /** @class */ (function () {
|
|
|
91
94
|
SubstrateKey.prototype.register = function (context) {
|
|
92
95
|
return __awaiter(this, void 0, void 0, function () {
|
|
93
96
|
var challenge, message, _a, _b;
|
|
94
|
-
var _c;
|
|
95
|
-
return __generator(this, function (
|
|
96
|
-
switch (
|
|
97
|
+
var _c, _d;
|
|
98
|
+
return __generator(this, function (_e) {
|
|
99
|
+
switch (_e.label) {
|
|
97
100
|
case 0: return [4 /*yield*/, this.getChallenge(context, this.addressGenerator(this.hashedUserId))];
|
|
98
101
|
case 1:
|
|
99
|
-
challenge =
|
|
102
|
+
challenge = _e.sent();
|
|
100
103
|
message = types_ts_1.SignedMessage.enc({
|
|
101
104
|
context: context,
|
|
102
105
|
authority_id: exports.KREIVO_AUTHORITY_ID,
|
|
@@ -106,9 +109,13 @@ var SubstrateKey = /** @class */ (function () {
|
|
|
106
109
|
message: types_ts_1.SignedMessage.dec(message),
|
|
107
110
|
public: polkadot_api_1.Binary.fromBytes(this.signer.publicKey)
|
|
108
111
|
};
|
|
112
|
+
_d = {
|
|
113
|
+
type: this.signer.signingType
|
|
114
|
+
};
|
|
109
115
|
_b = (_a = polkadot_api_1.Binary).fromBytes;
|
|
110
116
|
return [4 /*yield*/, this.signer.sign(message)];
|
|
111
|
-
case 2: return [2 /*return*/, (_c.signature = _b.apply(_a, [
|
|
117
|
+
case 2: return [2 /*return*/, (_c.signature = (_d.value = _b.apply(_a, [_e.sent()]),
|
|
118
|
+
_d),
|
|
112
119
|
_c)];
|
|
113
120
|
}
|
|
114
121
|
});
|
|
@@ -127,12 +134,12 @@ var SubstrateKey = /** @class */ (function () {
|
|
|
127
134
|
SubstrateKey.prototype.authenticate = function (context, xtc) {
|
|
128
135
|
return __awaiter(this, void 0, void 0, function () {
|
|
129
136
|
var challenge, message, _a, _b, _c, _d;
|
|
130
|
-
var _e, _f, _g;
|
|
131
|
-
return __generator(this, function (
|
|
132
|
-
switch (
|
|
137
|
+
var _e, _f, _g, _h;
|
|
138
|
+
return __generator(this, function (_j) {
|
|
139
|
+
switch (_j.label) {
|
|
133
140
|
case 0: return [4 /*yield*/, this.getChallenge(context, xtc)];
|
|
134
141
|
case 1:
|
|
135
|
-
challenge =
|
|
142
|
+
challenge = _j.sent();
|
|
136
143
|
message = {
|
|
137
144
|
context: context,
|
|
138
145
|
authority_id: exports.KREIVO_AUTHORITY_ID,
|
|
@@ -148,9 +155,13 @@ var SubstrateKey = /** @class */ (function () {
|
|
|
148
155
|
_g = {
|
|
149
156
|
message: message
|
|
150
157
|
};
|
|
158
|
+
_h = {
|
|
159
|
+
type: this.signer.signingType
|
|
160
|
+
};
|
|
151
161
|
_d = (_c = polkadot_api_1.Binary).fromBytes;
|
|
152
162
|
return [4 /*yield*/, this.signer.sign(types_ts_1.SignedMessage.enc(message))];
|
|
153
|
-
case 2: return [2 /*return*/, (_e.credentials = (_f.value = _b.apply(_a, [(_g.signature = _d.apply(_c, [
|
|
163
|
+
case 2: return [2 /*return*/, (_e.credentials = (_f.value = _b.apply(_a, [(_g.signature = (_h.value = _d.apply(_c, [_j.sent()]),
|
|
164
|
+
_h),
|
|
154
165
|
_g)]),
|
|
155
166
|
_f),
|
|
156
167
|
_e)];
|
package/dist/cjs/types.js
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KeySignature = exports.SignedMessage = void 0;
|
|
3
|
+
exports.KeySignature = exports.KeyRegistration = exports.SignedMessage = exports.MultiSignature = void 0;
|
|
4
4
|
var substrate_bindings_1 = require("@polkadot-api/substrate-bindings");
|
|
5
5
|
var scale_ts_1 = require("scale-ts");
|
|
6
|
+
exports.MultiSignature = (0, substrate_bindings_1.Variant)({
|
|
7
|
+
Ed25519: (0, substrate_bindings_1.Bin)(64),
|
|
8
|
+
Sr25519: (0, substrate_bindings_1.Bin)(64),
|
|
9
|
+
Ecdsa: (0, substrate_bindings_1.Bin)(65),
|
|
10
|
+
Eth: (0, substrate_bindings_1.Bin)(65),
|
|
11
|
+
});
|
|
6
12
|
exports.SignedMessage = (0, scale_ts_1.Struct)({
|
|
7
13
|
context: scale_ts_1.u32,
|
|
8
|
-
challenge: (0, substrate_bindings_1.Bin)(),
|
|
14
|
+
challenge: (0, substrate_bindings_1.Bin)(32),
|
|
9
15
|
authority_id: (0, substrate_bindings_1.Bin)(32),
|
|
10
16
|
});
|
|
17
|
+
exports.KeyRegistration = (0, scale_ts_1.Struct)({
|
|
18
|
+
message: exports.SignedMessage,
|
|
19
|
+
public: (0, substrate_bindings_1.Bin)(32),
|
|
20
|
+
signature: exports.MultiSignature,
|
|
21
|
+
});
|
|
11
22
|
exports.KeySignature = (0, scale_ts_1.Struct)({
|
|
12
23
|
message: exports.SignedMessage,
|
|
13
|
-
signature:
|
|
24
|
+
signature: exports.MultiSignature,
|
|
14
25
|
});
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { AddressGenerator, Authenticator, Challenger, TPassAuthenticate } from "@virtonetwork/signer";
|
|
2
|
-
import { SubstrateSigner, TKeyRegistration } from "./types.ts";
|
|
2
|
+
import { KeyRegistration, KeySignature, SignedMessage, SubstrateSigner, TKeyRegistration, TKeySignature, TSignedMessage } from "./types.ts";
|
|
3
3
|
import { Binary } from "polkadot-api";
|
|
4
|
+
export type { SubstrateSigner, TKeyRegistration, TKeySignature, TSignedMessage, };
|
|
5
|
+
export { SignedMessage, KeySignature, KeyRegistration };
|
|
4
6
|
export declare const KREIVO_AUTHORITY_ID: Binary;
|
|
5
7
|
export declare class SubstrateKey implements Authenticator<number> {
|
|
6
8
|
readonly userId: string;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { kreivoPassDefaultAddressGenerator, } from "@virtonetwork/signer";
|
|
2
|
-
import { KeySignature, SignedMessage, } from "./types.js";
|
|
2
|
+
import { KeyRegistration, KeySignature, SignedMessage, } from "./types.js";
|
|
3
3
|
import { Binary } from "polkadot-api";
|
|
4
|
+
export { SignedMessage, KeySignature, KeyRegistration };
|
|
4
5
|
export const KREIVO_AUTHORITY_ID = Binary.fromText("kreivo_p".padEnd(32, "\0"));
|
|
5
6
|
export class SubstrateKey {
|
|
6
7
|
userId;
|
|
@@ -41,7 +42,10 @@ export class SubstrateKey {
|
|
|
41
42
|
return {
|
|
42
43
|
message: SignedMessage.dec(message),
|
|
43
44
|
public: Binary.fromBytes(this.signer.publicKey),
|
|
44
|
-
signature:
|
|
45
|
+
signature: {
|
|
46
|
+
type: this.signer.signingType,
|
|
47
|
+
value: Binary.fromBytes(await this.signer.sign(message)),
|
|
48
|
+
},
|
|
45
49
|
};
|
|
46
50
|
}
|
|
47
51
|
/**
|
|
@@ -67,7 +71,10 @@ export class SubstrateKey {
|
|
|
67
71
|
tag: "SubstrateKey",
|
|
68
72
|
value: KeySignature.enc({
|
|
69
73
|
message: message,
|
|
70
|
-
signature:
|
|
74
|
+
signature: {
|
|
75
|
+
type: this.signer.signingType,
|
|
76
|
+
value: Binary.fromBytes(await this.signer.sign(SignedMessage.enc(message))),
|
|
77
|
+
},
|
|
71
78
|
}),
|
|
72
79
|
},
|
|
73
80
|
};
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,23 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FixedSizeBinary } from "@polkadot-api/substrate-bindings";
|
|
2
2
|
import { Codec } from "scale-ts";
|
|
3
3
|
import { AuthorityId } from "@virtonetwork/signer";
|
|
4
4
|
export type SubstrateSigner = {
|
|
5
5
|
publicKey: Uint8Array;
|
|
6
|
+
signingType: "Ed25519" | "Sr25519" | "Ecdsa" | "Eth";
|
|
6
7
|
sign: (bytes: Uint8Array) => Promise<Uint8Array> | Uint8Array;
|
|
7
8
|
};
|
|
8
9
|
export type TSignedMessage<Cx> = {
|
|
9
10
|
context: Cx;
|
|
10
|
-
challenge:
|
|
11
|
+
challenge: FixedSizeBinary<32>;
|
|
11
12
|
authority_id: AuthorityId;
|
|
12
13
|
};
|
|
14
|
+
export type TMutiSignature = {
|
|
15
|
+
type: "Ed25519";
|
|
16
|
+
value: FixedSizeBinary<64>;
|
|
17
|
+
} | {
|
|
18
|
+
type: "Sr25519";
|
|
19
|
+
value: FixedSizeBinary<64>;
|
|
20
|
+
} | {
|
|
21
|
+
type: "Ecdsa";
|
|
22
|
+
value: FixedSizeBinary<65>;
|
|
23
|
+
} | {
|
|
24
|
+
type: "Eth";
|
|
25
|
+
value: FixedSizeBinary<65>;
|
|
26
|
+
};
|
|
27
|
+
export declare const MultiSignature: Codec<TMutiSignature>;
|
|
13
28
|
export declare const SignedMessage: Codec<TSignedMessage<number>>;
|
|
14
29
|
export type TKeyRegistration<Cx> = {
|
|
15
30
|
message: TSignedMessage<Cx>;
|
|
16
31
|
public: FixedSizeBinary<32>;
|
|
17
|
-
signature:
|
|
32
|
+
signature: TMutiSignature;
|
|
18
33
|
};
|
|
34
|
+
export declare const KeyRegistration: Codec<TKeyRegistration<number>>;
|
|
19
35
|
export type TKeySignature<Cx> = {
|
|
20
36
|
message: TSignedMessage<Cx>;
|
|
21
|
-
signature:
|
|
37
|
+
signature: TMutiSignature;
|
|
22
38
|
};
|
|
23
39
|
export declare const KeySignature: Codec<TKeySignature<number>>;
|
package/dist/esm/types.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
import { Bin } from "@polkadot-api/substrate-bindings";
|
|
1
|
+
import { Bin, Variant, } from "@polkadot-api/substrate-bindings";
|
|
2
2
|
import { Struct, u32 } from "scale-ts";
|
|
3
|
+
export const MultiSignature = Variant({
|
|
4
|
+
Ed25519: Bin(64),
|
|
5
|
+
Sr25519: Bin(64),
|
|
6
|
+
Ecdsa: Bin(65),
|
|
7
|
+
Eth: Bin(65),
|
|
8
|
+
});
|
|
3
9
|
export const SignedMessage = Struct({
|
|
4
10
|
context: u32,
|
|
5
|
-
challenge: Bin(),
|
|
11
|
+
challenge: Bin(32),
|
|
6
12
|
authority_id: Bin(32),
|
|
7
13
|
});
|
|
14
|
+
export const KeyRegistration = Struct({
|
|
15
|
+
message: SignedMessage,
|
|
16
|
+
public: Bin(32),
|
|
17
|
+
signature: MultiSignature,
|
|
18
|
+
});
|
|
8
19
|
export const KeySignature = Struct({
|
|
9
20
|
message: SignedMessage,
|
|
10
|
-
signature:
|
|
21
|
+
signature: MultiSignature,
|
|
11
22
|
});
|
package/package.json
CHANGED