@sig-net/midnight 0.15.0 → 0.16.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/README.md +113 -49
- package/dist/constants.d.ts +55 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +85 -5
- package/dist/constants.js.map +1 -1
- package/dist/ecdsa-attestation.d.ts +6 -5
- package/dist/ecdsa-attestation.d.ts.map +1 -1
- package/dist/ecdsa-attestation.js +5 -4
- package/dist/ecdsa-attestation.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/managed/compiler/contract-manifest.json +2 -2
- package/dist/managed/contract/index.js +31 -31
- package/dist/managed/contract/index.js.map +1 -1
- package/dist/signature-requests-state-reader.d.ts +23 -5
- package/dist/signature-requests-state-reader.d.ts.map +1 -1
- package/dist/signature-requests-state-reader.js +50 -5
- package/dist/signature-requests-state-reader.js.map +1 -1
- package/dist/signature-response-verification.d.ts +1 -1
- package/dist/signature-response-verification.d.ts.map +1 -1
- package/dist/signature-response-verification.js +3 -3
- package/dist/signature-response-verification.js.map +1 -1
- package/dist/signature-state-reading.js +2 -2
- package/dist/signature-state-reading.js.map +1 -1
- package/dist/signet-contract-events.d.ts +262 -0
- package/dist/signet-contract-events.d.ts.map +1 -0
- package/dist/signet-contract-events.js +266 -0
- package/dist/signet-contract-events.js.map +1 -0
- package/dist/signet-evtype2tx-requests.d.ts +4 -4
- package/dist/signet-evtype2tx-requests.d.ts.map +1 -1
- package/dist/signet-evtype2tx-requests.js +3 -3
- package/dist/signet-request-feed.d.ts +59 -34
- package/dist/signet-request-feed.d.ts.map +1 -1
- package/dist/signet-request-feed.js +95 -62
- package/dist/signet-request-feed.js.map +1 -1
- package/dist/signet-request-response-reader.d.ts +62 -55
- package/dist/signet-request-response-reader.d.ts.map +1 -1
- package/dist/signet-request-response-reader.js +85 -99
- package/dist/signet-request-response-reader.js.map +1 -1
- package/dist/signet-requests.js +2 -2
- package/dist/signet-requests.js.map +1 -1
- package/package.json +2 -2
- package/src/Signet.compact +43 -36
- package/dist/signet-contract-state-reader.d.ts +0 -247
- package/dist/signet-contract-state-reader.d.ts.map +0 -1
- package/dist/signet-contract-state-reader.js +0 -363
- package/dist/signet-contract-state-reader.js.map +0 -1
- package/dist/signet-request-resolver.d.ts +0 -60
- package/dist/signet-request-resolver.d.ts.map +0 -1
- package/dist/signet-request-resolver.js +0 -78
- package/dist/signet-request-resolver.js.map +0 -1
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { SignBidirectionalNotification } from "./signet-contract-state-reader.ts";
|
|
2
|
-
import type { SignetPublicStateSource } from "./signet-request-response-reader.ts";
|
|
3
|
-
import type { RequestIdHex, SignBidirectionalEvent } from "./signet-requests.ts";
|
|
4
|
-
/**
|
|
5
|
-
* A {@link SignBidirectionalNotification} resolved to the authenticated
|
|
6
|
-
* request it refers to: the request record read from `callerAddress`'s own
|
|
7
|
-
* ledger, with `requestId` confirmed to be a member of that contract's index.
|
|
8
|
-
*/
|
|
9
|
-
export interface ResolvedSignetRequest {
|
|
10
|
-
/**
|
|
11
|
-
* The contract whose authenticated state the request was read from — the
|
|
12
|
-
* epsilon-derivation predecessor. Key derivation keys off THIS, never off a
|
|
13
|
-
* field taken from the notification on faith.
|
|
14
|
-
*/
|
|
15
|
-
callerAddress: string;
|
|
16
|
-
/** The request id, confirmed to be a member of `callerAddress`'s index. */
|
|
17
|
-
requestId: RequestIdHex;
|
|
18
|
-
/** The authenticated request record to sign. */
|
|
19
|
-
request: SignBidirectionalEvent;
|
|
20
|
-
}
|
|
21
|
-
/** Everything a {@link SignetRequestResolver} needs. */
|
|
22
|
-
export interface SignetRequestResolverConfig {
|
|
23
|
-
/** Source of raw contract state, e.g. midnight-js's `indexerPublicDataProvider`. */
|
|
24
|
-
readonly source: SignetPublicStateSource;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Resolves {@link SignBidirectionalNotification}s to authenticated
|
|
28
|
-
* {@link ResolvedSignetRequest}s by reading the named caller's ledger and
|
|
29
|
-
* enforcing the membership check. Construct once and reuse: resolved records
|
|
30
|
-
* are immutable (their ledger key is their hash), so they are cached by request
|
|
31
|
-
* id and a repeated notification for the same request costs no query.
|
|
32
|
-
*
|
|
33
|
-
* NB the cache is keyed by request id, NOT by contract address: a caller
|
|
34
|
-
* contract's state grows as it stores new requests, so caching its state would
|
|
35
|
-
* make the resolver blind to later requests from the same caller. Caching the
|
|
36
|
-
* immutable resolved record instead is the same pattern
|
|
37
|
-
* {@link SignetRequestResponseReader.getSignatureRequest} uses.
|
|
38
|
-
*/
|
|
39
|
-
export declare class SignetRequestResolver {
|
|
40
|
-
private readonly source;
|
|
41
|
-
private readonly resolvedCache;
|
|
42
|
-
/**
|
|
43
|
-
* @param config - The state source to read caller ledgers through.
|
|
44
|
-
*/
|
|
45
|
-
constructor(config: SignetRequestResolverConfig);
|
|
46
|
-
/**
|
|
47
|
-
* Resolve a notification to its authenticated request, or `undefined` when it
|
|
48
|
-
* cannot be trusted: the caller contract has no state, or `requestId` is not
|
|
49
|
-
* a member of the map at `requestsPath` (forged, stale, wrong field,
|
|
50
|
-
* or not yet indexed — poll again). Never throws on an untrusted
|
|
51
|
-
* notification; a bad one is dropped, not surfaced as an error.
|
|
52
|
-
*
|
|
53
|
-
* @param requestId - The request id the notification was registered under
|
|
54
|
-
* (the registry map key — the V1 payload does not carry one).
|
|
55
|
-
* @param notification - The decoded notification.
|
|
56
|
-
* @returns The authenticated request, or `undefined` to drop the notification.
|
|
57
|
-
*/
|
|
58
|
-
resolve(requestId: RequestIdHex, notification: SignBidirectionalNotification): Promise<ResolvedSignetRequest | undefined>;
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=signet-request-resolver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signet-request-resolver.d.ts","sourceRoot":"","sources":["../src/signet-request-resolver.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EACvB,MAAM,sBAAsB,CAAC;AAE9B;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB,2EAA2E;IAC3E,SAAS,EAAE,YAAY,CAAC;IACxB,gDAAgD;IAChD,OAAO,EAAE,sBAAsB,CAAC;CACjC;AAED,wDAAwD;AACxD,MAAM,WAAW,2BAA2B;IAC1C,oFAAoF;IACpF,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;CAC1C;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0B;IAIjD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkD;IAEhF;;OAEG;gBACS,MAAM,EAAE,2BAA2B;IAI/C;;;;;;;;;;;OAWG;IACG,OAAO,CACX,SAAS,EAAE,YAAY,EACvB,YAAY,EAAE,6BAA6B,GAC1C,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;CA8B9C"}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
// Turn a SignBidirectionalNotification into an AUTHENTICATED request record.
|
|
2
|
-
// This is the security core of the discovery flow (see
|
|
3
|
-
// knowledge-base/caller-attribution.md): the notification says only WHERE to
|
|
4
|
-
// look; the request that gets signed is read from the named caller's own
|
|
5
|
-
// authenticated ledger, and the notification's `requestId` must be a member
|
|
6
|
-
// of that contract's request index. An attacker cannot write into a contract
|
|
7
|
-
// it does not control, so a forged notification can at most re-point at a
|
|
8
|
-
// legitimate request that already exists — never inject one.
|
|
9
|
-
//
|
|
10
|
-
// Key derivation stays f(callerAddress, path), keyed off the contract whose
|
|
11
|
-
// authenticated state was actually read — the notification registry is a
|
|
12
|
-
// pointer board, never an authority.
|
|
13
|
-
import { lookupSignetRequestAt } from "./signature-requests-state-reader.js";
|
|
14
|
-
/**
|
|
15
|
-
* Resolves {@link SignBidirectionalNotification}s to authenticated
|
|
16
|
-
* {@link ResolvedSignetRequest}s by reading the named caller's ledger and
|
|
17
|
-
* enforcing the membership check. Construct once and reuse: resolved records
|
|
18
|
-
* are immutable (their ledger key is their hash), so they are cached by request
|
|
19
|
-
* id and a repeated notification for the same request costs no query.
|
|
20
|
-
*
|
|
21
|
-
* NB the cache is keyed by request id, NOT by contract address: a caller
|
|
22
|
-
* contract's state grows as it stores new requests, so caching its state would
|
|
23
|
-
* make the resolver blind to later requests from the same caller. Caching the
|
|
24
|
-
* immutable resolved record instead is the same pattern
|
|
25
|
-
* {@link SignetRequestResponseReader.getSignatureRequest} uses.
|
|
26
|
-
*/
|
|
27
|
-
export class SignetRequestResolver {
|
|
28
|
-
source;
|
|
29
|
-
// Resolved records never change; cache them so a redelivered notification for
|
|
30
|
-
// the same request id does not re-query the caller's state.
|
|
31
|
-
resolvedCache = new Map();
|
|
32
|
-
/**
|
|
33
|
-
* @param config - The state source to read caller ledgers through.
|
|
34
|
-
*/
|
|
35
|
-
constructor(config) {
|
|
36
|
-
this.source = config.source;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Resolve a notification to its authenticated request, or `undefined` when it
|
|
40
|
-
* cannot be trusted: the caller contract has no state, or `requestId` is not
|
|
41
|
-
* a member of the map at `requestsPath` (forged, stale, wrong field,
|
|
42
|
-
* or not yet indexed — poll again). Never throws on an untrusted
|
|
43
|
-
* notification; a bad one is dropped, not surfaced as an error.
|
|
44
|
-
*
|
|
45
|
-
* @param requestId - The request id the notification was registered under
|
|
46
|
-
* (the registry map key — the V1 payload does not carry one).
|
|
47
|
-
* @param notification - The decoded notification.
|
|
48
|
-
* @returns The authenticated request, or `undefined` to drop the notification.
|
|
49
|
-
*/
|
|
50
|
-
async resolve(requestId, notification) {
|
|
51
|
-
const cached = this.resolvedCache.get(requestId);
|
|
52
|
-
if (cached !== undefined) {
|
|
53
|
-
return cached;
|
|
54
|
-
}
|
|
55
|
-
let state;
|
|
56
|
-
try {
|
|
57
|
-
state = await this.source.queryContractState(notification.callerAddress);
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
return undefined; // caller address not a contract / transient read error
|
|
61
|
-
}
|
|
62
|
-
if (!state?.data) {
|
|
63
|
-
return undefined; // no state at the named caller — cannot authenticate
|
|
64
|
-
}
|
|
65
|
-
const request = lookupSignetRequestAt(state.data, notification.requestsPath, requestId);
|
|
66
|
-
if (request === undefined) {
|
|
67
|
-
return undefined; // membership check failed — drop the notification
|
|
68
|
-
}
|
|
69
|
-
const resolved = {
|
|
70
|
-
callerAddress: notification.callerAddress,
|
|
71
|
-
requestId,
|
|
72
|
-
request,
|
|
73
|
-
};
|
|
74
|
-
this.resolvedCache.set(requestId, resolved);
|
|
75
|
-
return resolved;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
//# sourceMappingURL=signet-request-resolver.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signet-request-resolver.js","sourceRoot":"","sources":["../src/signet-request-resolver.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,uDAAuD;AACvD,6EAA6E;AAC7E,yEAAyE;AACzE,4EAA4E;AAC5E,6EAA6E;AAC7E,0EAA0E;AAC1E,6DAA6D;AAC7D,EAAE;AACF,4EAA4E;AAC5E,yEAAyE;AACzE,qCAAqC;AAErC,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAiC7E;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,qBAAqB;IACf,MAAM,CAA0B;IAEjD,8EAA8E;IAC9E,4DAA4D;IAC3C,aAAa,GAAG,IAAI,GAAG,EAAuC,CAAC;IAEhF;;OAEG;IACH,YAAY,MAAmC;QAC7C,IAAI,C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