@pax2pay/model-banking 0.1.254 → 0.1.255

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/Account/index.ts CHANGED
@@ -10,6 +10,7 @@ export interface Account extends Account.Creatable {
10
10
  readonly created: isoly.DateTime
11
11
  readonly balances: Balances
12
12
  readonly rails: Rail.Address[]
13
+ key?: string
13
14
  //readonly rules: Rule[]
14
15
  }
15
16
 
@@ -20,6 +21,7 @@ export namespace Account {
20
21
  created: isly.fromIs("isoly.DateTime", isoly.DateTime.is),
21
22
  balances: isly.fromIs("Balances", Balances.is),
22
23
  rails: isly.fromIs("Rail.Address", Rail.Address.is).array(),
24
+ key: isly.string().optional(),
23
25
  })
24
26
  export const is = type.is
25
27
  export const flaw = type.flaw
@@ -0,0 +1,18 @@
1
+ import { cryptly } from "cryptly"
2
+ import type { Operation } from "./index"
3
+
4
+ export class Signer {
5
+ private readonly signer = cryptly.Signer.create("RSA", "SHA-256", this.keys.public, this.keys.private)
6
+
7
+ private constructor(private readonly keys: { public?: string; private?: string }) {}
8
+ async sign(operation: Operation & { previous: string }): Promise<string> {
9
+ return this.signer.sign(JSON.stringify(operation))
10
+ }
11
+ async verify(operation: Operation): Promise<boolean> {
12
+ return this.signer.verify(JSON.stringify({ ...operation, signature: undefined }), operation.signature ?? "")
13
+ }
14
+
15
+ static open(keys: { public?: string; private?: string }): Signer {
16
+ return new Signer(keys)
17
+ }
18
+ }
@@ -2,14 +2,17 @@ import { isoly } from "isoly"
2
2
  import { isly } from "isly"
3
3
  import { Changes as OperationChanges } from "./Changes"
4
4
  import { Creatable as OperationCreatable } from "./Creatable"
5
+ import { Signer as OperationSigner } from "./Signer"
5
6
 
6
7
  export interface Operation extends OperationCreatable {
7
8
  transaction: string
8
9
  counter: number
9
10
  created: isoly.DateTime
10
11
  signature?: string
12
+ previous?: string
11
13
  }
12
14
  export namespace Operation {
15
+ export const Signer = OperationSigner
13
16
  export type Creatable = OperationCreatable
14
17
  export const Creatable = OperationCreatable
15
18
  export type Changes = OperationChanges
@@ -22,21 +25,16 @@ export namespace Operation {
22
25
  counter: isly.number(),
23
26
  created: isly.fromIs("isoly.DateTime", isoly.DateTime.is),
24
27
  signature: isly.string().optional(),
28
+ previous: isly.string().optional(),
25
29
  })
26
30
  export const is = type.is
27
31
  export const flaw = type.flaw
28
- //TODO: actual signing function
29
- function sign(precursor: string): string | undefined {
30
- const signature = Number.parseInt(precursor)
31
- return Number.isNaN(signature) ? undefined : (signature + 1).toString()
32
- }
33
- export function fromCreatable(transaction: string, creatable: Creatable, oldSignature?: string): Operation {
32
+ export function fromCreatable(transaction: string, creatable: Creatable): Operation {
34
33
  return {
35
34
  ...creatable,
36
35
  transaction,
37
36
  counter: 0,
38
37
  created: isoly.DateTime.now(),
39
- signature: oldSignature && sign(oldSignature),
40
38
  }
41
39
  }
42
40
  }
@@ -9,6 +9,7 @@ export interface Account extends Account.Creatable {
9
9
  readonly created: isoly.DateTime;
10
10
  readonly balances: Balances;
11
11
  readonly rails: Rail.Address[];
12
+ key?: string;
12
13
  }
13
14
  export declare namespace Account {
14
15
  const type: isly.object.ExtendableType<Account>;
@@ -12,6 +12,7 @@ export var Account;
12
12
  created: isly.fromIs("isoly.DateTime", isoly.DateTime.is),
13
13
  balances: isly.fromIs("Balances", Balances.is),
14
14
  rails: isly.fromIs("Rail.Address", Rail.Address.is).array(),
15
+ key: isly.string().optional(),
15
16
  });
16
17
  Account.is = Account.type.is;
17
18
  Account.flaw = Account.type.flaw;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../","sources":["Account/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,E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EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAW3D,MAAM,KAAW,OAAO,CAiBvB;AAjBD,WAAiB,OAAO;IACV,YAAI,GAAG,IAAI,CAAC,MAAM,CAAU;QACxC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;QACnB,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE;QACjB,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzD,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC;QAC9C,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE;QAC3D,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KAC7B,CAAC,CAAA;IACW,UAAE,GAAG,QAAA,IAAI,CAAC,EAAE,CAAA;IACZ,YAAI,GAAG,QAAA,IAAI,CAAC,IAAI,CAAA;IAC7B,SAAgB,YAAY,CAAC,KAA+B;QAC3D,OAAO,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IACvC,CAAC;IAFe,oBAAY,eAE3B,CAAA;IAGY,iBAAS,GAAG,gBAAgB,CAAA;AAC1C,CAAC,EAjBgB,OAAO,KAAP,OAAO,QAiBvB"}
@@ -0,0 +1,14 @@
1
+ import type { Operation } from "./index";
2
+ export declare class Signer {
3
+ private readonly keys;
4
+ private readonly signer;
5
+ private constructor();
6
+ sign(operation: Operation & {
7
+ previous: string;
8
+ }): Promise<string>;
9
+ verify(operation: Operation): Promise<boolean>;
10
+ static open(keys: {
11
+ public?: string;
12
+ private?: string;
13
+ }): Signer;
14
+ }
@@ -0,0 +1,17 @@
1
+ import { cryptly } from "cryptly";
2
+ export class Signer {
3
+ constructor(keys) {
4
+ this.keys = keys;
5
+ this.signer = cryptly.Signer.create("RSA", "SHA-256", this.keys.public, this.keys.private);
6
+ }
7
+ async sign(operation) {
8
+ return this.signer.sign(JSON.stringify(operation));
9
+ }
10
+ async verify(operation) {
11
+ return this.signer.verify(JSON.stringify({ ...operation, signature: undefined }), operation.signature ?? "");
12
+ }
13
+ static open(keys) {
14
+ return new Signer(keys);
15
+ }
16
+ }
17
+ //# sourceMappingURL=Signer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Signer.js","sourceRoot":"../","sources":["Operation/Signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAGjC,MAAM,OAAO,MAAM;IAGlB,YAAqC,IAA2C;QAA3C,SAAI,GAAJ,IAAI,CAAuC;QAF/D,WAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAEnB,CAAC;IACpF,KAAK,CAAC,IAAI,CAAC,SAA2C;QACrD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAA;IACnD,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,SAAoB;QAChC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,CAAC,SAAS,IAAI,EAAE,CAAC,CAAA;IAC7G,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,IAA2C;QACtD,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,CAAA;IACxB,CAAC;CACD"}
@@ -2,13 +2,16 @@ import { isoly } from "isoly";
2
2
  import { isly } from "isly";
3
3
  import { Changes as OperationChanges } from "./Changes";
4
4
  import { Creatable as OperationCreatable } from "./Creatable";
5
+ import { Signer as OperationSigner } from "./Signer";
5
6
  export interface Operation extends OperationCreatable {
6
7
  transaction: string;
7
8
  counter: number;
8
9
  created: isoly.DateTime;
9
10
  signature?: string;
11
+ previous?: string;
10
12
  }
11
13
  export declare namespace Operation {
14
+ const Signer: typeof OperationSigner;
12
15
  type Creatable = OperationCreatable;
13
16
  const Creatable: typeof OperationCreatable;
14
17
  type Changes = OperationChanges;
@@ -19,5 +22,5 @@ export declare namespace Operation {
19
22
  const type: isly.object.ExtendableType<Operation>;
20
23
  const is: isly.Type.IsFunction<Operation>;
21
24
  const flaw: isly.Type.FlawFunction;
22
- function fromCreatable(transaction: string, creatable: Creatable, oldSignature?: string): Operation;
25
+ function fromCreatable(transaction: string, creatable: Creatable): Operation;
23
26
  }
@@ -2,8 +2,10 @@ import { isoly } from "isoly";
2
2
  import { isly } from "isly";
3
3
  import { Changes as OperationChanges } from "./Changes";
4
4
  import { Creatable as OperationCreatable } from "./Creatable";
5
+ import { Signer as OperationSigner } from "./Signer";
5
6
  export var Operation;
6
7
  (function (Operation) {
8
+ Operation.Signer = OperationSigner;
7
9
  Operation.Creatable = OperationCreatable;
8
10
  Operation.Changes = OperationChanges;
9
11
  Operation.type = OperationCreatable.type.extend({
@@ -11,20 +13,16 @@ export var Operation;
11
13
  counter: isly.number(),
12
14
  created: isly.fromIs("isoly.DateTime", isoly.DateTime.is),
13
15
  signature: isly.string().optional(),
16
+ previous: isly.string().optional(),
14
17
  });
15
18
  Operation.is = Operation.type.is;
16
19
  Operation.flaw = Operation.type.flaw;
17
- function sign(precursor) {
18
- const signature = Number.parseInt(precursor);
19
- return Number.isNaN(signature) ? undefined : (signature + 1).toString();
20
- }
21
- function fromCreatable(transaction, creatable, oldSignature) {
20
+ function fromCreatable(transaction, creatable) {
22
21
  return {
23
22
  ...creatable,
24
23
  transaction,
25
24
  counter: 0,
26
25
  created: isoly.DateTime.now(),
27
- signature: oldSignature && sign(oldSignature),
28
26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aAAa,CAAC,WAAmB,EAAE,SAAoB;QACtE,OAAO;YACN,GAAG,SAAS;YACZ,WAAW;YACX,OAAO,EAAE,CAAC;YACV,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE;SAC7B,CAAA;IACF,CAAC;IAPe,uBAAa,gBAO5B,CAAA;AACF,CAAC,EA1BgB,SAAS,KAAT,SAAS,QA0BzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pax2pay/model-banking",
3
- "version": "0.1.254",
3
+ "version": "0.1.255",
4
4
  "description": "Library containing data model types and functions for the Pax2Pay Banking API.",
5
5
  "author": "Pax2Pay Ltd",
6
6
  "license": "MIT",