@virtonetwork/authenticators-substrate 1.0.0 → 1.1.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/cjs/index.js CHANGED
@@ -91,12 +91,12 @@ var SubstrateKey = /** @class */ (function () {
91
91
  SubstrateKey.prototype.register = function (context) {
92
92
  return __awaiter(this, void 0, void 0, function () {
93
93
  var challenge, message, _a, _b;
94
- var _c;
95
- return __generator(this, function (_d) {
96
- switch (_d.label) {
94
+ var _c, _d;
95
+ return __generator(this, function (_e) {
96
+ switch (_e.label) {
97
97
  case 0: return [4 /*yield*/, this.getChallenge(context, this.addressGenerator(this.hashedUserId))];
98
98
  case 1:
99
- challenge = _d.sent();
99
+ challenge = _e.sent();
100
100
  message = types_ts_1.SignedMessage.enc({
101
101
  context: context,
102
102
  authority_id: exports.KREIVO_AUTHORITY_ID,
@@ -106,9 +106,13 @@ var SubstrateKey = /** @class */ (function () {
106
106
  message: types_ts_1.SignedMessage.dec(message),
107
107
  public: polkadot_api_1.Binary.fromBytes(this.signer.publicKey)
108
108
  };
109
+ _d = {
110
+ type: this.signer.signingType
111
+ };
109
112
  _b = (_a = polkadot_api_1.Binary).fromBytes;
110
113
  return [4 /*yield*/, this.signer.sign(message)];
111
- case 2: return [2 /*return*/, (_c.signature = _b.apply(_a, [_d.sent()]),
114
+ case 2: return [2 /*return*/, (_c.signature = (_d.value = _b.apply(_a, [_e.sent()]),
115
+ _d),
112
116
  _c)];
113
117
  }
114
118
  });
@@ -127,12 +131,12 @@ var SubstrateKey = /** @class */ (function () {
127
131
  SubstrateKey.prototype.authenticate = function (context, xtc) {
128
132
  return __awaiter(this, void 0, void 0, function () {
129
133
  var challenge, message, _a, _b, _c, _d;
130
- var _e, _f, _g;
131
- return __generator(this, function (_h) {
132
- switch (_h.label) {
134
+ var _e, _f, _g, _h;
135
+ return __generator(this, function (_j) {
136
+ switch (_j.label) {
133
137
  case 0: return [4 /*yield*/, this.getChallenge(context, xtc)];
134
138
  case 1:
135
- challenge = _h.sent();
139
+ challenge = _j.sent();
136
140
  message = {
137
141
  context: context,
138
142
  authority_id: exports.KREIVO_AUTHORITY_ID,
@@ -148,9 +152,13 @@ var SubstrateKey = /** @class */ (function () {
148
152
  _g = {
149
153
  message: message
150
154
  };
155
+ _h = {
156
+ type: this.signer.signingType
157
+ };
151
158
  _d = (_c = polkadot_api_1.Binary).fromBytes;
152
159
  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, [_h.sent()]),
160
+ case 2: return [2 /*return*/, (_e.credentials = (_f.value = _b.apply(_a, [(_g.signature = (_h.value = _d.apply(_c, [_j.sent()]),
161
+ _h),
154
162
  _g)]),
155
163
  _f),
156
164
  _e)];
package/dist/cjs/types.js CHANGED
@@ -1,8 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KeySignature = exports.SignedMessage = void 0;
3
+ exports.KeySignature = 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
14
  challenge: (0, substrate_bindings_1.Bin)(),
@@ -10,5 +16,5 @@ exports.SignedMessage = (0, scale_ts_1.Struct)({
10
16
  });
11
17
  exports.KeySignature = (0, scale_ts_1.Struct)({
12
18
  message: exports.SignedMessage,
13
- signature: (0, substrate_bindings_1.Bin)(),
19
+ signature: exports.MultiSignature,
14
20
  });
package/dist/esm/index.js CHANGED
@@ -41,7 +41,10 @@ export class SubstrateKey {
41
41
  return {
42
42
  message: SignedMessage.dec(message),
43
43
  public: Binary.fromBytes(this.signer.publicKey),
44
- signature: Binary.fromBytes(await this.signer.sign(message)),
44
+ signature: {
45
+ type: this.signer.signingType,
46
+ value: Binary.fromBytes(await this.signer.sign(message)),
47
+ },
45
48
  };
46
49
  }
47
50
  /**
@@ -67,7 +70,10 @@ export class SubstrateKey {
67
70
  tag: "SubstrateKey",
68
71
  value: KeySignature.enc({
69
72
  message: message,
70
- signature: Binary.fromBytes(await this.signer.sign(SignedMessage.enc(message))),
73
+ signature: {
74
+ type: this.signer.signingType,
75
+ value: Binary.fromBytes(await this.signer.sign(SignedMessage.enc(message))),
76
+ },
71
77
  }),
72
78
  },
73
79
  };
@@ -3,6 +3,7 @@ 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> = {
@@ -10,14 +11,28 @@ export type TSignedMessage<Cx> = {
10
11
  challenge: Binary;
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: AuthorityId;
32
+ signature: TMutiSignature;
18
33
  };
19
34
  export type TKeySignature<Cx> = {
20
35
  message: TSignedMessage<Cx>;
21
- signature: Binary;
36
+ signature: TMutiSignature;
22
37
  };
23
38
  export declare const KeySignature: Codec<TKeySignature<number>>;
package/dist/esm/types.js CHANGED
@@ -1,5 +1,11 @@
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
11
  challenge: Bin(),
@@ -7,5 +13,5 @@ export const SignedMessage = Struct({
7
13
  });
8
14
  export const KeySignature = Struct({
9
15
  message: SignedMessage,
10
- signature: Bin(),
16
+ signature: MultiSignature,
11
17
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@virtonetwork/authenticators-substrate",
3
3
  "description": "An Authenticator compatible with KreivoPassSigner that uses substrate-style signatures",
4
- "version": "1.0.0",
4
+ "version": "1.1.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"