@avow-finance/spec 0.6.0 → 0.8.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/agent-connect.d.ts +11 -3
- package/dist/agent-connect.d.ts.map +1 -1
- package/dist/agent-connect.js +4 -4
- package/dist/agent-connect.js.map +1 -1
- package/dist/agent-session.d.ts +10 -0
- package/dist/agent-session.d.ts.map +1 -1
- package/dist/api.d.ts +607 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +109 -77
- package/dist/api.js.map +1 -1
- package/dist/dependencies.d.ts.map +1 -1
- package/dist/dependencies.js +8 -2
- package/dist/dependencies.js.map +1 -1
- package/dist/eip712.d.ts +429 -16
- package/dist/eip712.d.ts.map +1 -1
- package/dist/eip712.js +97 -27
- package/dist/eip712.js.map +1 -1
- package/dist/gpu-reservation.d.ts.map +1 -1
- package/dist/gpu-reservation.js +1 -1
- package/dist/gpu-reservation.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/job-session.d.ts +20 -0
- package/dist/job-session.d.ts.map +1 -1
- package/dist/job.d.ts.map +1 -1
- package/dist/job.js +1 -1
- package/dist/job.js.map +1 -1
- package/dist/json-fields.d.ts +2 -0
- package/dist/json-fields.d.ts.map +1 -1
- package/dist/json-fields.js +2 -0
- package/dist/json-fields.js.map +1 -1
- package/dist/mailbox.d.ts +77 -104
- package/dist/mailbox.d.ts.map +1 -1
- package/dist/mailbox.js +8 -30
- package/dist/mailbox.js.map +1 -1
- package/dist/mandate-chain.d.ts +58 -0
- package/dist/mandate-chain.d.ts.map +1 -0
- package/dist/mandate-chain.js +79 -0
- package/dist/mandate-chain.js.map +1 -0
- package/dist/mandate-proof.d.ts +8 -4
- package/dist/mandate-proof.d.ts.map +1 -1
- package/dist/mandate-proof.js +16 -3
- package/dist/mandate-proof.js.map +1 -1
- package/dist/negotiation.d.ts +514 -0
- package/dist/negotiation.d.ts.map +1 -0
- package/dist/negotiation.js +490 -0
- package/dist/negotiation.js.map +1 -0
- package/dist/offer-search.d.ts +282 -0
- package/dist/offer-search.d.ts.map +1 -0
- package/dist/offer-search.js +252 -0
- package/dist/offer-search.js.map +1 -0
- package/dist/openapi.d.ts +47 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +571 -0
- package/dist/openapi.js.map +1 -0
- package/dist/order-wire.d.ts +73 -0
- package/dist/order-wire.d.ts.map +1 -0
- package/dist/order-wire.js +33 -0
- package/dist/order-wire.js.map +1 -0
- package/dist/reasons.d.ts +12 -2
- package/dist/reasons.d.ts.map +1 -1
- package/dist/reasons.js +12 -2
- package/dist/reasons.js.map +1 -1
- package/dist/sandbox.d.ts +104 -0
- package/dist/sandbox.d.ts.map +1 -1
- package/dist/sandbox.js +25 -0
- package/dist/sandbox.js.map +1 -1
- package/dist/service-order.d.ts +747 -0
- package/dist/service-order.d.ts.map +1 -0
- package/dist/service-order.js +182 -0
- package/dist/service-order.js.map +1 -0
- package/dist/service.d.ts +248 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +379 -0
- package/dist/service.js.map +1 -0
- package/dist/session-fields.d.ts +10 -0
- package/dist/session-fields.d.ts.map +1 -1
- package/dist/terms.d.ts +7 -4
- package/dist/terms.d.ts.map +1 -1
- package/dist/terms.js +12 -5
- package/dist/terms.js.map +1 -1
- package/dist/test-customer.d.ts +20 -0
- package/dist/test-customer.d.ts.map +1 -1
- package/dist/text.d.ts +5 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +5 -0
- package/dist/text.js.map +1 -0
- package/dist/types.d.ts +24 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -3
- package/dist/types.js.map +1 -1
- package/dist/version.d.ts +7 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +9 -1
- package/dist/version.js.map +1 -1
- package/dist/wire.d.ts +313 -0
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +29 -1
- package/dist/wire.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type Address, type Hex } from 'viem';
|
|
2
|
+
import { type AvowDomain } from './eip712.js';
|
|
3
|
+
import { type MandateProof } from './mandate-proof.js';
|
|
4
|
+
import type { ReasonCode } from './reasons.js';
|
|
5
|
+
import type { Parsed } from './wire.js';
|
|
6
|
+
/** The most mandates one agent's chain holds, the current one included. */
|
|
7
|
+
export declare const MAX_MANDATE_CHAIN = 64;
|
|
8
|
+
/**
|
|
9
|
+
* Every mandate an agent has held, as Avow serves them: the one it acts under now, and each one
|
|
10
|
+
* that mandate replaced, newest first. The last of `earlier` is the mandate the agent's key was
|
|
11
|
+
* put on with, or `current` is when the agent was never given another.
|
|
12
|
+
*/
|
|
13
|
+
export interface AgentMandates {
|
|
14
|
+
current: MandateProof;
|
|
15
|
+
earlier: MandateProof[];
|
|
16
|
+
}
|
|
17
|
+
/** An agent's mandates checked as one chain, with each mandate's hash. */
|
|
18
|
+
export interface MandateChain {
|
|
19
|
+
current: {
|
|
20
|
+
proof: MandateProof;
|
|
21
|
+
hash: Hex;
|
|
22
|
+
};
|
|
23
|
+
/** The hashes of the mandates the current one replaced, newest first. */
|
|
24
|
+
earlier: Hex[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parses the mandates Avow serves for one agent. Each has to parse as a mandate for the lock it
|
|
28
|
+
* names, and the chain can't hold more than `MAX_MANDATE_CHAIN`. It doesn't check that they link,
|
|
29
|
+
* which `mandateChainProblem` does.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseAgentMandates(json: unknown, expected: {
|
|
32
|
+
chainId: number;
|
|
33
|
+
lock: Address;
|
|
34
|
+
}): Parsed<AgentMandates>;
|
|
35
|
+
/**
|
|
36
|
+
* Checks an agent's mandates link into one chain that starts at the mandate its key was put on
|
|
37
|
+
* with, and returns each hash, or the reason they don't. Every mandate names the same account,
|
|
38
|
+
* business, agent and key. Each one after the first names the hash of the one before it in
|
|
39
|
+
* `replaces` and carries the account's signature, and the first names none and hashes to the key's
|
|
40
|
+
* witness on the chain. Hashes are worked out here, never taken from whoever served the chain, so
|
|
41
|
+
* a mandate can't be left out or slipped in without the links breaking.
|
|
42
|
+
* It checks no signature, since that takes the chain, which the verifier and Avow's API read.
|
|
43
|
+
*
|
|
44
|
+
* It says nothing about which mandate is current beyond the order Avow served. Avow decides that
|
|
45
|
+
* by approving reserves only under the current one, and the lock takes none without its approval.
|
|
46
|
+
*/
|
|
47
|
+
export declare function mandateChainProblem(mandates: AgentMandates, expected: {
|
|
48
|
+
domain: AvowDomain;
|
|
49
|
+
agentKey: Address;
|
|
50
|
+
witness: Hex;
|
|
51
|
+
}): {
|
|
52
|
+
ok: true;
|
|
53
|
+
value: MandateChain;
|
|
54
|
+
} | {
|
|
55
|
+
ok: false;
|
|
56
|
+
reason: ReasonCode;
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=mandate-chain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mandate-chain.d.ts","sourceRoot":"","sources":["../src/mandate-chain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,GAAG,EAAkB,MAAM,MAAM,CAAA;AAC7D,OAAO,EAAE,KAAK,UAAU,EAAe,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAmB,KAAK,YAAY,EAAqB,MAAM,oBAAoB,CAAA;AAC1F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAEvC,2EAA2E;AAC3E,eAAO,MAAM,iBAAiB,KAAK,CAAA;AAEnC;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,YAAY,CAAA;IACrB,OAAO,EAAE,YAAY,EAAE,CAAA;CACxB;AAED,0EAA0E;AAC1E,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE;QAAE,KAAK,EAAE,YAAY,CAAC;QAAC,IAAI,EAAE,GAAG,CAAA;KAAE,CAAA;IAC3C,yEAAyE;IACzE,OAAO,EAAE,GAAG,EAAE,CAAA;CACf;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,OAAO,EACb,QAAQ,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC3C,MAAM,CAAC,aAAa,CAAC,CAevB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,aAAa,EACvB,QAAQ,EAAE;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,GAChE;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CAmCvE"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { isAddressEqual } from 'viem';
|
|
2
|
+
import { mandateHash } from './eip712.js';
|
|
3
|
+
import { isSignedMandate, parseMandateProof } from './mandate-proof.js';
|
|
4
|
+
/** The most mandates one agent's chain holds, the current one included. */
|
|
5
|
+
export const MAX_MANDATE_CHAIN = 64;
|
|
6
|
+
/**
|
|
7
|
+
* Parses the mandates Avow serves for one agent. Each has to parse as a mandate for the lock it
|
|
8
|
+
* names, and the chain can't hold more than `MAX_MANDATE_CHAIN`. It doesn't check that they link,
|
|
9
|
+
* which `mandateChainProblem` does.
|
|
10
|
+
*/
|
|
11
|
+
export function parseAgentMandates(json, expected) {
|
|
12
|
+
if (typeof json !== 'object' || json === null)
|
|
13
|
+
return { ok: false, reason: 'message.invalid' };
|
|
14
|
+
const { current, earlier } = json;
|
|
15
|
+
if (!Array.isArray(earlier) || earlier.length >= MAX_MANDATE_CHAIN) {
|
|
16
|
+
return { ok: false, reason: 'message.invalid' };
|
|
17
|
+
}
|
|
18
|
+
const head = parseMandateProof(current, expected);
|
|
19
|
+
if (!head.ok)
|
|
20
|
+
return head;
|
|
21
|
+
const rest = [];
|
|
22
|
+
for (const e of earlier) {
|
|
23
|
+
const read = parseMandateProof(e, expected);
|
|
24
|
+
if (!read.ok)
|
|
25
|
+
return read;
|
|
26
|
+
rest.push(read.value);
|
|
27
|
+
}
|
|
28
|
+
return { ok: true, value: { current: head.value, earlier: rest } };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Checks an agent's mandates link into one chain that starts at the mandate its key was put on
|
|
32
|
+
* with, and returns each hash, or the reason they don't. Every mandate names the same account,
|
|
33
|
+
* business, agent and key. Each one after the first names the hash of the one before it in
|
|
34
|
+
* `replaces` and carries the account's signature, and the first names none and hashes to the key's
|
|
35
|
+
* witness on the chain. Hashes are worked out here, never taken from whoever served the chain, so
|
|
36
|
+
* a mandate can't be left out or slipped in without the links breaking.
|
|
37
|
+
* It checks no signature, since that takes the chain, which the verifier and Avow's API read.
|
|
38
|
+
*
|
|
39
|
+
* It says nothing about which mandate is current beyond the order Avow served. Avow decides that
|
|
40
|
+
* by approving reserves only under the current one, and the lock takes none without its approval.
|
|
41
|
+
*/
|
|
42
|
+
export function mandateChainProblem(mandates, expected) {
|
|
43
|
+
const no = (reason) => ({ ok: false, reason });
|
|
44
|
+
const all = [mandates.current, ...mandates.earlier];
|
|
45
|
+
const first = mandates.current.message;
|
|
46
|
+
if (!isAddressEqual(first.agentKey, expected.agentKey))
|
|
47
|
+
return no('agent.key_mismatch');
|
|
48
|
+
for (const { message: m } of all) {
|
|
49
|
+
if (!isAddressEqual(m.account, first.account) ||
|
|
50
|
+
!isAddressEqual(m.agentKey, first.agentKey) ||
|
|
51
|
+
m.businessId !== first.businessId ||
|
|
52
|
+
m.agentId !== first.agentId) {
|
|
53
|
+
return no('message.invalid');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const hashes = all.map((p) => mandateHash(p.message, expected.domain));
|
|
57
|
+
for (let i = 0; i < all.length - 1; i++) {
|
|
58
|
+
const later = all[i];
|
|
59
|
+
if (later.message.replaces?.toLowerCase() !== hashes[i + 1]?.toLowerCase()) {
|
|
60
|
+
return no('mandate.replaces_mismatch');
|
|
61
|
+
}
|
|
62
|
+
if (!isSignedMandate(later))
|
|
63
|
+
return no('message.invalid');
|
|
64
|
+
}
|
|
65
|
+
const oldest = all[all.length - 1];
|
|
66
|
+
if (oldest.message.replaces !== undefined)
|
|
67
|
+
return no('mandate.replaces_mismatch');
|
|
68
|
+
if (hashes[hashes.length - 1]?.toLowerCase() !== expected.witness.toLowerCase()) {
|
|
69
|
+
return no('chain.mandate_mismatch');
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
ok: true,
|
|
73
|
+
value: {
|
|
74
|
+
current: { proof: mandates.current, hash: hashes[0] },
|
|
75
|
+
earlier: hashes.slice(1),
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=mandate-chain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mandate-chain.js","sourceRoot":"","sources":["../src/mandate-chain.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,cAAc,EAAE,MAAM,MAAM,CAAA;AAC7D,OAAO,EAAmB,WAAW,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAqB,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAI1F,2EAA2E;AAC3E,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAA;AAmBnC;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAChC,IAAa,EACb,QAA4C;IAE5C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK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AK,SAAS;QAAE,OAAO,EAAE,CAAC,2BAA2B,CAAC,CAAA;IACjF,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;QAChF,OAAO,EAAE,CAAC,wBAAwB,CAAC,CAAA;IACrC,CAAC;IACD,OAAO;QACL,EAAE,EAAE,IAAI;QACR,KAAK,EAAE;YACL,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAQ,EAAE;YAC5D,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;SACzB;KACF,CAAA;AACH,CAAC"}
|
package/dist/mandate-proof.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Address, Hex } from 'viem';
|
|
2
|
-
import type
|
|
3
|
-
import type { Mandate } from './types.js';
|
|
2
|
+
import { type Signed } from './eip712.js';
|
|
3
|
+
import type { FirstMandate, Mandate } from './types.js';
|
|
4
4
|
import { type Parsed } from './wire.js';
|
|
5
5
|
/**
|
|
6
6
|
* A mandate the business account authorized in a transaction, with no signature of its own. In
|
|
@@ -8,9 +8,10 @@ import { type Parsed } from './wire.js';
|
|
|
8
8
|
* witness, which only the account's root or an admin key can do, so the transaction is the
|
|
9
9
|
* account's word on exactly this mandate. One passkey prompt then covers the mandate, the key and
|
|
10
10
|
* its limits. The envelope is the one a signed mandate carries, so a reader checks the same chain
|
|
11
|
-
* and lock, and `mandateHash` hashes the message the same way.
|
|
11
|
+
* and lock, and `mandateHash` hashes the message the same way. Only a first mandate can be shown
|
|
12
|
+
* this way, since the transaction bound the first mandate's hash and no later one.
|
|
12
13
|
*/
|
|
13
|
-
export type AuthorizedMandate = Omit<Signed<
|
|
14
|
+
export type AuthorizedMandate = Omit<Signed<FirstMandate>, 'signature'> & {
|
|
14
15
|
/** The transaction that put the agent's key on the account with this mandate's hash. */
|
|
15
16
|
authorizedIn: Hex;
|
|
16
17
|
};
|
|
@@ -24,6 +25,9 @@ export declare const isSignedMandate: (proof: MandateProof) => proof is Signed<M
|
|
|
24
25
|
/**
|
|
25
26
|
* Parses a mandate with its proof and checks its envelope as `parseSigned` does. A mandate
|
|
26
27
|
* carries either a signature or the transaction that authorized it, never both and never neither.
|
|
28
|
+
* Its envelope's version has to be the one its message signs at, so a replacement can't pass as a
|
|
29
|
+
* first mandate or the reverse. A replacement needs the account's signature, since the transaction
|
|
30
|
+
* that put the key on bound the first mandate's hash and no later one.
|
|
27
31
|
*/
|
|
28
32
|
export declare function parseMandateProof(json: unknown, expected: {
|
|
29
33
|
chainId: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mandate-proof.d.ts","sourceRoot":"","sources":["../src/mandate-proof.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AACxC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"mandate-proof.d.ts","sourceRoot":"","sources":["../src/mandate-proof.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AACxC,OAAO,EAAkB,KAAK,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzD,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEvD,OAAO,EAAe,KAAK,MAAM,EAAe,MAAM,WAAW,CAAA;AAEjE;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,WAAW,CAAC,GAAG;IACxE,wFAAwF;IACxF,YAAY,EAAE,GAAG,CAAA;CAClB,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,iBAAiB,CAAA;AAE9D,eAAO,MAAM,eAAe,UAAW,YAAY,KAAG,KAAK,IAAI,MAAM,CAAC,OAAO,CACvD,CAAA;AAEtB;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,OAAO,EACb,QAAQ,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,GAC5C,MAAM,CAAC,YAAY,CAAC,CAqBtB"}
|
package/dist/mandate-proof.js
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
|
+
import { mandateVersion } from './eip712.js';
|
|
1
2
|
import { bytes32 } from './json-fields.js';
|
|
3
|
+
import { MESSAGE_VERSIONS } from './version.js';
|
|
2
4
|
import { mandateJson, parseSigned } from './wire.js';
|
|
3
5
|
export const isSignedMandate = (proof) => 'signature' in proof;
|
|
4
6
|
/**
|
|
5
7
|
* Parses a mandate with its proof and checks its envelope as `parseSigned` does. A mandate
|
|
6
8
|
* carries either a signature or the transaction that authorized it, never both and never neither.
|
|
9
|
+
* Its envelope's version has to be the one its message signs at, so a replacement can't pass as a
|
|
10
|
+
* first mandate or the reverse. A replacement needs the account's signature, since the transaction
|
|
11
|
+
* that put the key on bound the first mandate's hash and no later one.
|
|
7
12
|
*/
|
|
8
13
|
export function parseMandateProof(json, expected) {
|
|
9
14
|
if (typeof json !== 'object' || json === null || !('authorizedIn' in json)) {
|
|
10
|
-
|
|
15
|
+
const signed = parseSigned(json, 'Mandate', mandateJson, expected);
|
|
16
|
+
if (signed.ok && signed.value.schemaVersion !== mandateVersion(signed.value.message)) {
|
|
17
|
+
return { ok: false, reason: 'message.invalid' };
|
|
18
|
+
}
|
|
19
|
+
return signed;
|
|
11
20
|
}
|
|
12
21
|
const { authorizedIn, ...envelope } = json;
|
|
13
22
|
const tx = bytes32.safeParse(authorizedIn);
|
|
@@ -18,7 +27,11 @@ export function parseMandateProof(json, expected) {
|
|
|
18
27
|
const read = parseSigned({ ...envelope, signature: '0x' }, 'Mandate', mandateJson, expected);
|
|
19
28
|
if (!read.ok)
|
|
20
29
|
return read;
|
|
21
|
-
const { signature: _, ...rest } = read.value;
|
|
22
|
-
|
|
30
|
+
const { signature: _, message, ...rest } = read.value;
|
|
31
|
+
const { replaces, ...first } = message;
|
|
32
|
+
if (replaces !== undefined || rest.schemaVersion !== MESSAGE_VERSIONS.Mandate) {
|
|
33
|
+
return { ok: false, reason: 'message.invalid' };
|
|
34
|
+
}
|
|
35
|
+
return { ok: true, value: { ...rest, message: first, authorizedIn: tx.data } };
|
|
23
36
|
}
|
|
24
37
|
//# sourceMappingURL=mandate-proof.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mandate-proof.js","sourceRoot":"","sources":["../src/mandate-proof.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mandate-proof.js","sourceRoot":"","sources":["../src/mandate-proof.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAe,MAAM,aAAa,CAAA;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAe,WAAW,EAAE,MAAM,WAAW,CAAA;AAuBjE,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAmB,EAA4B,EAAE,CAC/E,WAAW,IAAI,KAAK,CAAA;AAEtB;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,IAAa,EACb,QAA6C;IAE7C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC,cAAc,IAAI,IAAI,CAAC,EAAE,CAAC;QAC3E,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAA;QAClE,IAAI,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC,KAAK,CAAC,aAAa,KAAK,cAAc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