@truealter/sdk 0.4.1 → 0.5.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 +49 -36
- package/dist/bin/alter-identity.js +19 -13
- package/dist/bin/mcp-bridge.js +30 -9
- package/dist/index.cjs +42 -13
- package/dist/index.d.cts +391 -27
- package/dist/index.d.ts +391 -27
- package/dist/index.js +38 -14
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { p256 } from '@noble/curves/p256';
|
|
2
2
|
import { sha256 } from '@noble/hashes/sha256';
|
|
3
3
|
import { randomBytes, bytesToHex as bytesToHex$1, hexToBytes } from '@noble/hashes/utils';
|
|
4
|
+
import { createPrivateKey, createHash } from 'crypto';
|
|
4
5
|
import * as ed25519 from '@noble/ed25519';
|
|
5
6
|
import { sha512 } from '@noble/hashes/sha512';
|
|
6
7
|
import { spawnSync } from 'child_process';
|
|
@@ -8,18 +9,11 @@ import { homedir, platform } from 'os';
|
|
|
8
9
|
import { join, resolve, dirname } from 'path';
|
|
9
10
|
import { env } from 'process';
|
|
10
11
|
import { existsSync, readFileSync, mkdirSync, writeFileSync, copyFileSync, renameSync, unlinkSync } from 'fs';
|
|
11
|
-
import { createHash } from 'crypto';
|
|
12
12
|
|
|
13
13
|
var __defProp = Object.defineProperty;
|
|
14
14
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
15
15
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
16
16
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
18
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
19
|
-
}) : x)(function(x) {
|
|
20
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
21
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
22
|
-
});
|
|
23
17
|
var __esm = (fn, res) => function __init() {
|
|
24
18
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
25
19
|
};
|
|
@@ -104,8 +98,7 @@ function loadPrivateKey(key) {
|
|
|
104
98
|
return key;
|
|
105
99
|
}
|
|
106
100
|
if (typeof key === "string" && key.includes("-----BEGIN")) {
|
|
107
|
-
const
|
|
108
|
-
const keyObj = nodeCrypto.createPrivateKey({ key, format: "pem" });
|
|
101
|
+
const keyObj = createPrivateKey({ key, format: "pem" });
|
|
109
102
|
const jwk = keyObj.export({ format: "jwk" });
|
|
110
103
|
if (jwk.crv !== "P-256" || !jwk.d) {
|
|
111
104
|
throw new TypeError("PEM is not a P-256 private key.");
|
|
@@ -501,6 +494,7 @@ var MCPClient = class {
|
|
|
501
494
|
clientInfo;
|
|
502
495
|
x402;
|
|
503
496
|
signing;
|
|
497
|
+
extraHeaders;
|
|
504
498
|
requestCounter = 0;
|
|
505
499
|
initialised = false;
|
|
506
500
|
constructor(opts = {}) {
|
|
@@ -512,6 +506,7 @@ var MCPClient = class {
|
|
|
512
506
|
this.clientInfo = opts.clientInfo ?? { name: "@truealter/sdk", version: "0.2.0" };
|
|
513
507
|
this.x402 = opts.x402;
|
|
514
508
|
this.signing = opts.signing;
|
|
509
|
+
this.extraHeaders = opts.extraHeaders;
|
|
515
510
|
}
|
|
516
511
|
/**
|
|
517
512
|
* Send the MCP `initialize` handshake and capture the resulting session
|
|
@@ -675,6 +670,7 @@ var MCPClient = class {
|
|
|
675
670
|
}
|
|
676
671
|
buildHeaders(extra) {
|
|
677
672
|
const headers = {
|
|
673
|
+
...this.extraHeaders ?? {},
|
|
678
674
|
"Content-Type": "application/json",
|
|
679
675
|
Accept: "application/json",
|
|
680
676
|
"User-Agent": `${this.clientInfo.name}/${this.clientInfo.version}`
|
|
@@ -815,6 +811,7 @@ var DEFAULT_VERIFY_AT_ALLOWLIST = Object.freeze([
|
|
|
815
811
|
"api.truealter.com",
|
|
816
812
|
"mcp.truealter.com"
|
|
817
813
|
]);
|
|
814
|
+
var ALTER_PLATFORM_ISS = "did:alter:platform";
|
|
818
815
|
async function verifyProvenance(envelope, opts = {}) {
|
|
819
816
|
const token = typeof envelope === "string" ? envelope : envelope.token;
|
|
820
817
|
if (!token) return { valid: false, reason: "empty token" };
|
|
@@ -897,6 +894,15 @@ async function verifyProvenance(envelope, opts = {}) {
|
|
|
897
894
|
if (typeof payload.iat === "number" && payload.iat > now + 300) {
|
|
898
895
|
return { valid: false, reason: "issued in the future", payload, kid: header.kid };
|
|
899
896
|
}
|
|
897
|
+
const expectedIss = opts.expectedIss !== void 0 ? opts.expectedIss : ALTER_PLATFORM_ISS;
|
|
898
|
+
if (expectedIss !== "" && payload.iss !== expectedIss) {
|
|
899
|
+
return {
|
|
900
|
+
valid: false,
|
|
901
|
+
reason: `iss mismatch: expected "${expectedIss}", got "${payload.iss}"`,
|
|
902
|
+
payload,
|
|
903
|
+
kid: header.kid
|
|
904
|
+
};
|
|
905
|
+
}
|
|
900
906
|
return { valid: true, payload, kid: header.kid };
|
|
901
907
|
}
|
|
902
908
|
async function verifyToolSignatures(tools, signatures) {
|
|
@@ -1093,10 +1099,10 @@ var AlterClient = class {
|
|
|
1093
1099
|
}
|
|
1094
1100
|
/** Verify a person is registered with ALTER (handle or id). */
|
|
1095
1101
|
async verify(handleOrId, claims) {
|
|
1096
|
-
const args = handleOrId.includes("@") ? {
|
|
1097
|
-
// ~handle — server resolves these via the
|
|
1098
|
-
{
|
|
1099
|
-
) : {
|
|
1102
|
+
const args = handleOrId.includes("@") ? { member_id: "", email: handleOrId } : handleOrId.startsWith("~") ? (
|
|
1103
|
+
// ~handle — server resolves these via the member_id field
|
|
1104
|
+
{ member_id: handleOrId }
|
|
1105
|
+
) : { member_id: handleOrId };
|
|
1100
1106
|
if (claims) args.claims = claims;
|
|
1101
1107
|
return this.mcp.callTool("verify_identity", args);
|
|
1102
1108
|
}
|
|
@@ -1890,4 +1896,22 @@ var TOOL_BLAST_RADIUS = {
|
|
|
1890
1896
|
query_graph_similarity: "high"
|
|
1891
1897
|
};
|
|
1892
1898
|
|
|
1893
|
-
|
|
1899
|
+
// src/homepage.ts
|
|
1900
|
+
var HOMEPAGE_LIMITS = {
|
|
1901
|
+
whoami_max_chars: 240,
|
|
1902
|
+
opener_max_chars: 280,
|
|
1903
|
+
pronouns_max_chars: 32,
|
|
1904
|
+
attunement_glyph_max_chars: 16
|
|
1905
|
+
};
|
|
1906
|
+
|
|
1907
|
+
// src/themes.ts
|
|
1908
|
+
var THEME_LIMITS = {
|
|
1909
|
+
meta_name_pattern: /^[a-z][a-z0-9-]{0,63}$/,
|
|
1910
|
+
meta_description_max_chars: 240,
|
|
1911
|
+
opener_library_max_entries: 32,
|
|
1912
|
+
opener_entry_max_chars: 240,
|
|
1913
|
+
share_note_max_chars: 280
|
|
1914
|
+
};
|
|
1915
|
+
var OSC8_ALLOWED_SCHEMES = ["https:", "mailto:"];
|
|
1916
|
+
|
|
1917
|
+
export { ALL_CLIENTS, AlterAuthError, AlterClient, AlterDiscoveryError, AlterError, AlterInvalidResponse, AlterNetworkError, AlterPaymentRequired, AlterProvenanceError, AlterRateLimited, AlterTimeoutError, AlterToolError, CLAUDE_CODE, CLAUDE_DESKTOP, CURSOR, DEFAULT_DOMAIN, DEFAULT_ENDPOINT, DEFAULT_VERIFY_AT_ALLOWLIST, FREE_TOOL_NAMES, HOMEPAGE_LIMITS, MCPClient, MCP_PROTOCOL_VERSION, OSC8_ALLOWED_SCHEMES, PREMIUM_TOOL_NAMES, SDK_NAME, SDK_VERSION, THEME_LIMITS, TOOL_BLAST_RADIUS, TOOL_COSTS, TOOL_TIERS, VSCODE, X402Client, base64urlDecode, base64urlEncode2 as base64urlEncode, canonicalArgsSha256, canonicalStringify, clearDiscoveryCache, decodeDid, detectSyncedVolume, discover, encodeDid, fetchPublicKeys, generateClaudeConfig, generateClaudeDesktopConfig, generateCursorConfig, generateGenericMcpConfig, generateKeypair, keypairFromPrivateKey, loadPrivateKey, parsePaymentHeader, probeAll, probeByDir, probeClaudeCode, readWireState, resolveVerifyAt, sha2562 as sha256, sign, signInvocation, unwire, verify, verifyProvenance, verifyToolSignatures, wire, writeWireState };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truealter/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "ALTER Identity SDK — query the continuous identity field from any JavaScript/TypeScript environment",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"prepublishOnly": "npm run build"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@noble/curves": "
|
|
40
|
-
"@noble/ed25519": "
|
|
41
|
-
"@noble/hashes": "
|
|
39
|
+
"@noble/curves": "1.9.7",
|
|
40
|
+
"@noble/ed25519": "2.3.0",
|
|
41
|
+
"@noble/hashes": "1.8.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/node": "^20.11.0",
|