@calimero-network/mero-js 23.5.0 → 23.7.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/admin-api/admin-types.d.ts +14 -0
- package/dist/cloud/account-ownership.d.ts +9 -1
- package/dist/cloud/account-ownership.js +8 -2
- package/dist/cloud/cloud-client.d.ts +38 -2
- package/dist/cloud/cloud-client.js +48 -8
- package/dist/cloud/index.d.ts +1 -1
- package/dist/cloud/index.js +1 -1
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +3 -3
- package/dist/index.cjs +45 -7
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +45 -7
- package/dist/index.mjs.map +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -35,6 +35,7 @@ __export(index_exports, {
|
|
|
35
35
|
EphemeralClient: () => EphemeralClient,
|
|
36
36
|
HANDSHAKE_PATH: () => HANDSHAKE_PATH,
|
|
37
37
|
HTTPError: () => HTTPError,
|
|
38
|
+
HaRequestPendingError: () => HaRequestPendingError,
|
|
38
39
|
INVITED_ROLE: () => INVITED_ROLE,
|
|
39
40
|
IntentRefusedError: () => IntentRefusedError,
|
|
40
41
|
LocalStorageTokenStore: () => LocalStorageTokenStore,
|
|
@@ -47,6 +48,7 @@ __export(index_exports, {
|
|
|
47
48
|
PRESENCE_DOMAIN: () => PRESENCE_DOMAIN,
|
|
48
49
|
REQUEST_PROOF_HEADER: () => REQUEST_PROOF_HEADER,
|
|
49
50
|
RelayClient: () => RelayClient,
|
|
51
|
+
RelayNotDialableError: () => RelayNotDialableError,
|
|
50
52
|
RelayObserver: () => RelayObserver,
|
|
51
53
|
RelayPresenceClient: () => RelayPresenceClient,
|
|
52
54
|
RelayTransport: () => RelayTransport,
|
|
@@ -58,6 +60,7 @@ __export(index_exports, {
|
|
|
58
60
|
SealedTransportError: () => SealedTransportError,
|
|
59
61
|
SseClient: () => SseClient,
|
|
60
62
|
StaleTransportKeyError: () => StaleTransportKeyError,
|
|
63
|
+
UnknownRelayError: () => UnknownRelayError,
|
|
61
64
|
WarrantNonceExhaustedError: () => WarrantNonceExhaustedError,
|
|
62
65
|
WarrantNonceRouteUnavailableError: () => WarrantNonceRouteUnavailableError,
|
|
63
66
|
WebHttpClient: () => WebHttpClient,
|
|
@@ -3696,6 +3699,7 @@ async function resolveSigner(secret, signer, label2) {
|
|
|
3696
3699
|
var DOMAIN = new TextEncoder().encode("calimero.mdma.account-ownership-claim.v1\0");
|
|
3697
3700
|
var DEFAULT_TTL_MS = 6e4;
|
|
3698
3701
|
var MAX_TTL_MS = 5 * 6e4;
|
|
3702
|
+
var MAX_RELAY_URL = 1024;
|
|
3699
3703
|
var ACCOUNT_OWNERSHIP_AUDIENCE = "mdma:enable-ha-namespace";
|
|
3700
3704
|
var ACCOUNT_HA_AUDIENCE = "mdma:enable-ha-namespace-as-account";
|
|
3701
3705
|
function base64(bytes) {
|
|
@@ -3707,7 +3711,10 @@ var hex32 = (value, what) => {
|
|
|
3707
3711
|
if (!/^[0-9a-fA-F]{64}$/.test(value)) throw new Error(`${what} must be 64 hex characters`);
|
|
3708
3712
|
return value.toLowerCase();
|
|
3709
3713
|
};
|
|
3710
|
-
async function signClaim(input, audience, subject) {
|
|
3714
|
+
async function signClaim(input, audience, subject, relayUrl) {
|
|
3715
|
+
if (relayUrl !== void 0 && !(relayUrl.length > 0 && relayUrl.length <= MAX_RELAY_URL)) {
|
|
3716
|
+
throw new Error(`relayUrl must be a non-empty string of at most ${MAX_RELAY_URL} characters`);
|
|
3717
|
+
}
|
|
3711
3718
|
const ttl = input.ttlMs ?? DEFAULT_TTL_MS;
|
|
3712
3719
|
if (!(ttl > 0 && ttl <= MAX_TTL_MS)) throw new Error(`ttlMs must be in (0, ${MAX_TTL_MS}]`);
|
|
3713
3720
|
const groupId = hex32(input.namespaceId, "namespaceId");
|
|
@@ -3726,7 +3733,8 @@ async function signClaim(input, audience, subject) {
|
|
|
3726
3733
|
...subject === void 0 ? {} : { subject },
|
|
3727
3734
|
nonce: nonce2,
|
|
3728
3735
|
issued_at_ms: issued,
|
|
3729
|
-
expires_at_ms: issued + ttl
|
|
3736
|
+
expires_at_ms: issued + ttl,
|
|
3737
|
+
...relayUrl === void 0 ? {} : { relay_url: relayUrl }
|
|
3730
3738
|
})
|
|
3731
3739
|
);
|
|
3732
3740
|
const signature = await signer.sign(concat(DOMAIN, payload));
|
|
@@ -3737,7 +3745,7 @@ async function signAccountOwnershipClaim(input) {
|
|
|
3737
3745
|
return signClaim(input, ACCOUNT_OWNERSHIP_AUDIENCE, input.subject);
|
|
3738
3746
|
}
|
|
3739
3747
|
async function signAccountHaClaim(input) {
|
|
3740
|
-
return signClaim(input, ACCOUNT_HA_AUDIENCE, void 0);
|
|
3748
|
+
return signClaim(input, ACCOUNT_HA_AUDIENCE, void 0, input.relayUrl);
|
|
3741
3749
|
}
|
|
3742
3750
|
|
|
3743
3751
|
// src/device-cert/device-cert.ts
|
|
@@ -6162,6 +6170,31 @@ var AccountLinkedToSeveralUsersError = class extends AccountHaRefusedError {
|
|
|
6162
6170
|
}
|
|
6163
6171
|
};
|
|
6164
6172
|
AccountLinkedToSeveralUsersError.CODE = "account_linked_to_several_users";
|
|
6173
|
+
var HaRequestPendingError = class extends AccountHaRefusedError {
|
|
6174
|
+
constructor() {
|
|
6175
|
+
super(...arguments);
|
|
6176
|
+
this.name = "HaRequestPendingError";
|
|
6177
|
+
}
|
|
6178
|
+
};
|
|
6179
|
+
HaRequestPendingError.CODE = "ha_request_pending";
|
|
6180
|
+
var UnknownRelayError = class extends AccountHaRefusedError {
|
|
6181
|
+
constructor() {
|
|
6182
|
+
super(...arguments);
|
|
6183
|
+
this.name = "UnknownRelayError";
|
|
6184
|
+
}
|
|
6185
|
+
};
|
|
6186
|
+
UnknownRelayError.CODE = "unknown_relay";
|
|
6187
|
+
var RelayNotDialableError = class extends AccountHaRefusedError {
|
|
6188
|
+
constructor() {
|
|
6189
|
+
super(...arguments);
|
|
6190
|
+
this.name = "RelayNotDialableError";
|
|
6191
|
+
}
|
|
6192
|
+
};
|
|
6193
|
+
RelayNotDialableError.CODE = "relay_not_dialable";
|
|
6194
|
+
var ACCOUNT_HA_REFUSALS = {
|
|
6195
|
+
409: [AccountNotLinkedError, AccountLinkedToSeveralUsersError, HaRequestPendingError],
|
|
6196
|
+
422: [UnknownRelayError, RelayNotDialableError]
|
|
6197
|
+
};
|
|
6165
6198
|
function conflictCode(bodyText) {
|
|
6166
6199
|
if (!bodyText) return void 0;
|
|
6167
6200
|
try {
|
|
@@ -6584,7 +6617,11 @@ var CloudClient = class {
|
|
|
6584
6617
|
* Pass merod's response object straight through. The cloud accepts core's
|
|
6585
6618
|
* `signerPublicKey`/`signedPayload` casing as well as snake_case, so there is
|
|
6586
6619
|
* no re-keying step — and getting that wrong used to surface as a `422`
|
|
6587
|
-
* naming three missing fields.
|
|
6620
|
+
* naming three missing fields. Passing it whole also carries the `founding`
|
|
6621
|
+
* and `credential` merod attaches: the cloud accepts a namespace proof only
|
|
6622
|
+
* from a node of the account that founded the namespace, checked with those
|
|
6623
|
+
* two, and only when that account is linked to this login. A node that
|
|
6624
|
+
* predates them, or an admin that did not found the namespace, gets a `422`.
|
|
6588
6625
|
*
|
|
6589
6626
|
* Idempotent for the same account. A namespace already claimed by someone
|
|
6590
6627
|
* else is a `409`; a replayed proof nonce is a `403`.
|
|
@@ -6659,7 +6696,8 @@ var CloudClient = class {
|
|
|
6659
6696
|
credential: options.credential,
|
|
6660
6697
|
deviceSecret: options.deviceSecret,
|
|
6661
6698
|
signer: options.signer,
|
|
6662
|
-
ttlMs: options.ttlMs
|
|
6699
|
+
ttlMs: options.ttlMs,
|
|
6700
|
+
relayUrl: options.relayUrl
|
|
6663
6701
|
});
|
|
6664
6702
|
const account = options.accountId.toLowerCase();
|
|
6665
6703
|
const namespace = options.namespaceId.toLowerCase();
|
|
@@ -6670,9 +6708,9 @@ var CloudClient = class {
|
|
|
6670
6708
|
{ body: { ownership_proof: proof }, anonymous: true }
|
|
6671
6709
|
);
|
|
6672
6710
|
} catch (err) {
|
|
6673
|
-
if (err instanceof HTTPError && err.status
|
|
6711
|
+
if (err instanceof HTTPError && ACCOUNT_HA_REFUSALS[err.status]) {
|
|
6674
6712
|
const code = conflictCode(err.bodyText);
|
|
6675
|
-
const Typed =
|
|
6713
|
+
const Typed = ACCOUNT_HA_REFUSALS[err.status].find((t) => t.CODE === code);
|
|
6676
6714
|
if (Typed && code) {
|
|
6677
6715
|
throw new Typed(code, err.status, err.statusText, err.url, err.headers, err.bodyText);
|
|
6678
6716
|
}
|