@hwlt/era-connect 0.1.0 → 0.3.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 +25 -5
- package/cardano/package.json +6 -0
- package/dist/cardano-DP6U_K1J.cjs +105 -0
- package/dist/cardano-DP6U_K1J.cjs.map +1 -0
- package/dist/cardano-Do1ahUlK.d.cts +62 -0
- package/dist/cardano-OzjWZHh6.d.ts +62 -0
- package/dist/cardano-yuOygqwp.js +94 -0
- package/dist/cardano-yuOygqwp.js.map +1 -0
- package/dist/cardano.cjs +10 -0
- package/dist/cardano.d.cts +3 -0
- package/dist/cardano.d.ts +3 -0
- package/dist/cardano.js +3 -0
- package/dist/derive-C4JdycUh.js +117 -0
- package/dist/derive-C4JdycUh.js.map +1 -0
- package/dist/derive-CuILJRPT.cjs +176 -0
- package/dist/derive-CuILJRPT.cjs.map +1 -0
- package/dist/index.cjs +133 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +64 -7
- package/dist/index.d.ts +64 -7
- package/dist/index.js +120 -85
- package/dist/index.js.map +1 -1
- package/dist/ton-5Uvi5ifg.js +86 -0
- package/dist/ton-5Uvi5ifg.js.map +1 -0
- package/dist/ton-C0UP-cf_.d.ts +51 -0
- package/dist/ton-DUJGXdGa.cjs +97 -0
- package/dist/ton-DUJGXdGa.cjs.map +1 -0
- package/dist/ton-DmeIvknN.d.cts +51 -0
- package/dist/ton.cjs +10 -0
- package/dist/ton.d.cts +3 -0
- package/dist/ton.d.ts +3 -0
- package/dist/ton.js +3 -0
- package/dist/verify.cjs +302 -13
- package/dist/verify.cjs.map +1 -1
- package/dist/verify.d.cts +56 -1
- package/dist/verify.d.ts +56 -1
- package/dist/verify.js +301 -15
- package/dist/verify.js.map +1 -1
- package/package.json +32 -8
- package/ton/package.json +6 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ton-5Uvi5ifg.js","names":["UrValue"],"sources":["../src/chains/ton.ts"],"sourcesContent":["import { cborEncode } from '../cbor/encode';\nimport type { CborValue } from '../cbor/model';\nimport { cbBytes, cbMap, cbTag, cbText, cbUint, mapGet, stripTags } from '../cbor/model';\nimport { equalBytes, utf8Encode } from '../core/bytes';\nimport { EraSdkError } from '../core/errors';\nimport { normalizeRequestId, uuidStringify } from '../core/rand';\nimport { keypath304, normalizeXfp, parsePath } from '../registry/keypath';\nimport type { Ur } from '../ur/ur';\nimport { Ur as UrValue } from '../ur/ur';\nimport type { ChainContext, EraConnectConfig, ExpectedReply, SignRequest } from './shared';\nimport {\n makeSignRequest,\n requireReplyMap,\n requireUrType,\n resolveContext,\n resolveRequestId,\n toUr,\n} from './shared';\n\n/** `ton-sign-request` dataType (CBOR key 3). */\nexport const TonDataType = {\n /** `signData` is a Bag-of-Cells; the device signs the ROOT CELL's representation hash. */\n transaction: 1,\n /**\n * TON Connect proof: the device signs\n * `sha256(0xFFFF || \"ton-connect\" || sha256(signData))`.\n */\n tonProof: 2,\n} as const;\nexport type TonDataType = (typeof TonDataType)[keyof typeof TonDataType];\n\nexport interface TonSignRequestProps {\n readonly requestId?: Uint8Array | string;\n /** BoC bytes (transaction) or the raw proof payload (tonProof). */\n readonly signData: Uint8Array;\n /** Defaults to `transaction`. */\n readonly dataType?: TonDataType;\n /** The account path, e.g. `m/44'/607'/0'` (V4R2 and V5R1 share it — the wallet-contract version affects only the address). */\n readonly path: string;\n readonly xfp: string | number;\n /** User-friendly bounceable address TEXT (`UQ…`/`EQ…`) — shown on the device. */\n readonly address?: string;\n readonly origin?: string;\n}\n\nexport interface TonSignatureResult {\n readonly requestId: Uint8Array;\n /** 64-byte Ed25519 signature over the digest for the request's dataType. */\n readonly signature: Uint8Array;\n}\n\nconst REPLY_TYPES = ['ton-signature'] as const;\n\nexport class TonChain {\n static readonly DataType = TonDataType;\n\n private readonly context: ChainContext;\n\n constructor(config?: EraConnectConfig) {\n this.context = resolveContext(config);\n }\n\n /** Build a `ton-sign-request` (7201). Reply: `ton-signature` (7202). */\n generateSignRequest(props: TonSignRequestProps): SignRequest<TonSignatureResult> {\n const requestId = resolveRequestId(this.context, props.requestId);\n const path = parsePath(props.path);\n const xfp = normalizeXfp(props.xfp);\n if (props.signData.length === 0) {\n throw new EraSdkError('invalid-props', 'signData must not be empty');\n }\n\n const entries: [number, CborValue][] = [\n // TON ecosystem quirk: the request id travels as the ASCII BYTES of the\n // hyphenated UUID string, wrapped in tag 37 (that is what Tonkeeper-\n // style integrations emit and what the device echoes back verbatim).\n [1, cbTag(37, cbBytes(utf8Encode(uuidStringify(requestId))))],\n [2, cbBytes(props.signData)],\n [3, cbUint(props.dataType ?? TonDataType.transaction)],\n [4, keypath304(path, xfp)],\n ];\n if (props.address !== undefined) entries.push([5, cbText(props.address)]);\n entries.push([6, cbText(props.origin ?? this.context.origin)]);\n\n const ur = new UrValue('ton-sign-request', cborEncode(cbMap(entries)));\n return makeSignRequest({\n ur,\n requestId,\n replyTypes: REPLY_TYPES,\n context: this.context,\n parse: (reply) => parseTonSignature(reply, requestId),\n });\n }\n\n /** Parse a `ton-signature` standalone. Prefer `SignRequest.scanner().parse()`. */\n parseSignature(input: Ur | string, expect?: ExpectedReply): TonSignatureResult {\n return parseTonSignature(\n toUr(input),\n expect?.requestId === undefined ? undefined : normalizeRequestId(expect.requestId),\n );\n }\n}\n\nfunction parseTonSignature(ur: Ur, expectedRequestId: Uint8Array | undefined): TonSignatureResult {\n requireUrType(ur, [...REPLY_TYPES], 'ton-signature');\n const map = requireReplyMap(ur, 'ton-signature');\n\n // The device echoes the request id BYTES verbatim (tag-37 wrapped). On this\n // chain those bytes are normally the ASCII of the UUID string; a bare\n // 16-byte binary echo is accepted too for forward compatibility.\n const echoedValue = mapGet(map, 1);\n const echoed = echoedValue === undefined ? undefined : stripTags(echoedValue);\n if (echoed?.kind !== 'bytes') {\n throw new EraSdkError('malformed-reply', 'ton-signature does not echo the request id (key 1)');\n }\n const requestId = normalizeEchoedId(echoed.value);\n if (expectedRequestId !== undefined) {\n if (requestId === null || !equalBytes(requestId, expectedRequestId)) {\n throw new EraSdkError(\n 'request-id-mismatch',\n 'ton-signature echoes a different request id — it answers another sign request, not this one',\n );\n }\n }\n\n const sigValue = mapGet(map, 2);\n const sig = sigValue === undefined ? undefined : stripTags(sigValue);\n if (sig?.kind !== 'bytes') {\n throw new EraSdkError('malformed-reply', 'ton-signature is missing the signature (key 2)');\n }\n if (sig.value.length !== 64) {\n throw new EraSdkError(\n 'malformed-reply',\n `ton-signature signature is ${sig.value.length} bytes, expected 64`,\n );\n }\n return { requestId: requestId ?? new Uint8Array(16), signature: sig.value };\n}\n\n/** ASCII-UUID-string bytes (36) or raw binary (16) → 16-byte id; null if neither. */\nfunction normalizeEchoedId(echoed: Uint8Array): Uint8Array | null {\n if (echoed.length === 16) return echoed;\n if (echoed.length === 36) {\n let text = '';\n for (const b of echoed) {\n if (b > 0x7f) return null;\n text += String.fromCharCode(b);\n }\n try {\n return normalizeRequestId(text);\n } catch {\n return null;\n }\n }\n return null;\n}\n"],"mappings":";;;AAoBA,MAAa,cAAc;;CAEzB,aAAa;;;;;CAKb,UAAU;AACZ;AAuBA,MAAM,cAAc,CAAC,eAAe;AAEpC,IAAa,WAAb,MAAsB;CAKpB,YAAY,QAA2B;EACrC,KAAK,UAAU,eAAe,MAAM;CACtC;;CAGA,oBAAoB,OAA6D;EAC/E,MAAM,YAAY,iBAAiB,KAAK,SAAS,MAAM,SAAS;EAChE,MAAM,OAAO,UAAU,MAAM,IAAI;EACjC,MAAM,MAAM,aAAa,MAAM,GAAG;EAClC,IAAI,MAAM,SAAS,WAAW,GAC5B,MAAM,IAAI,YAAY,iBAAiB,4BAA4B;EAGrE,MAAM,UAAiC;GAIrC,CAAC,GAAG,MAAM,IAAI,QAAQ,WAAW,cAAc,SAAS,CAAC,CAAC,CAAC,CAAC;GAC5D,CAAC,GAAG,QAAQ,MAAM,QAAQ,CAAC;GAC3B,CAAC,GAAG,OAAO,MAAM,YAAY,YAAY,WAAW,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AAI,YACR,mBACA,8BAA8B,IAAI,MAAM,OAAO,oBACjD;CAEF,OAAO;EAAE,WAAW,6BAAa,IAAI,WAAW,EAAE;EAAG,WAAW,IAAI;CAAM;AAC5E;;AAGA,SAAS,kBAAkB,QAAuC;CAChE,IAAI,OAAO,WAAW,IAAI,OAAO;CACjC,IAAI,OAAO,WAAW,IAAI;EACxB,IAAI,OAAO;EACX,KAAK,MAAM,KAAK,QAAQ;GACtB,IAAI,IAAI,KAAM,OAAO;GACrB,QAAQ,OAAO,aAAa,CAAC;EAC/B;EACA,IAAI;GACF,OAAO,mBAAmB,IAAI;EAChC,QAAQ;GACN,OAAO;EACT;CACF;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { _ as Ur, a as SignRequest, i as ExpectedReply, r as EraConnectConfig } from "./shared-CI8zhQiE.js";
|
|
2
|
+
//#region src/chains/ton.d.ts
|
|
3
|
+
/** `ton-sign-request` dataType (CBOR key 3). */
|
|
4
|
+
declare const TonDataType: {
|
|
5
|
+
/** `signData` is a Bag-of-Cells; the device signs the ROOT CELL's representation hash. */
|
|
6
|
+
readonly transaction: 1;
|
|
7
|
+
/**
|
|
8
|
+
* TON Connect proof: the device signs
|
|
9
|
+
* `sha256(0xFFFF || "ton-connect" || sha256(signData))`.
|
|
10
|
+
*/
|
|
11
|
+
readonly tonProof: 2;
|
|
12
|
+
};
|
|
13
|
+
type TonDataType = (typeof TonDataType)[keyof typeof TonDataType];
|
|
14
|
+
interface TonSignRequestProps {
|
|
15
|
+
readonly requestId?: Uint8Array | string;
|
|
16
|
+
/** BoC bytes (transaction) or the raw proof payload (tonProof). */
|
|
17
|
+
readonly signData: Uint8Array;
|
|
18
|
+
/** Defaults to `transaction`. */
|
|
19
|
+
readonly dataType?: TonDataType;
|
|
20
|
+
/** The account path, e.g. `m/44'/607'/0'` (V4R2 and V5R1 share it — the wallet-contract version affects only the address). */
|
|
21
|
+
readonly path: string;
|
|
22
|
+
readonly xfp: string | number;
|
|
23
|
+
/** User-friendly bounceable address TEXT (`UQ…`/`EQ…`) — shown on the device. */
|
|
24
|
+
readonly address?: string;
|
|
25
|
+
readonly origin?: string;
|
|
26
|
+
}
|
|
27
|
+
interface TonSignatureResult {
|
|
28
|
+
readonly requestId: Uint8Array;
|
|
29
|
+
/** 64-byte Ed25519 signature over the digest for the request's dataType. */
|
|
30
|
+
readonly signature: Uint8Array;
|
|
31
|
+
}
|
|
32
|
+
declare class TonChain {
|
|
33
|
+
static readonly DataType: {
|
|
34
|
+
/** `signData` is a Bag-of-Cells; the device signs the ROOT CELL's representation hash. */
|
|
35
|
+
readonly transaction: 1;
|
|
36
|
+
/**
|
|
37
|
+
* TON Connect proof: the device signs
|
|
38
|
+
* `sha256(0xFFFF || "ton-connect" || sha256(signData))`.
|
|
39
|
+
*/
|
|
40
|
+
readonly tonProof: 2;
|
|
41
|
+
};
|
|
42
|
+
private readonly context;
|
|
43
|
+
constructor(config?: EraConnectConfig);
|
|
44
|
+
/** Build a `ton-sign-request` (7201). Reply: `ton-signature` (7202). */
|
|
45
|
+
generateSignRequest(props: TonSignRequestProps): SignRequest<TonSignatureResult>;
|
|
46
|
+
/** Parse a `ton-signature` standalone. Prefer `SignRequest.scanner().parse()`. */
|
|
47
|
+
parseSignature(input: Ur | string, expect?: ExpectedReply): TonSignatureResult;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { TonSignatureResult as i, TonDataType as n, TonSignRequestProps as r, TonChain as t };
|
|
51
|
+
//# sourceMappingURL=ton-C0UP-cf_.d.ts.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const require_shared = require("./shared-nISrEktU.cjs");
|
|
2
|
+
//#region src/chains/ton.ts
|
|
3
|
+
/** `ton-sign-request` dataType (CBOR key 3). */
|
|
4
|
+
const TonDataType = {
|
|
5
|
+
/** `signData` is a Bag-of-Cells; the device signs the ROOT CELL's representation hash. */
|
|
6
|
+
transaction: 1,
|
|
7
|
+
/**
|
|
8
|
+
* TON Connect proof: the device signs
|
|
9
|
+
* `sha256(0xFFFF || "ton-connect" || sha256(signData))`.
|
|
10
|
+
*/
|
|
11
|
+
tonProof: 2
|
|
12
|
+
};
|
|
13
|
+
const REPLY_TYPES = ["ton-signature"];
|
|
14
|
+
var TonChain = class {
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this.context = require_shared.resolveContext(config);
|
|
17
|
+
}
|
|
18
|
+
/** Build a `ton-sign-request` (7201). Reply: `ton-signature` (7202). */
|
|
19
|
+
generateSignRequest(props) {
|
|
20
|
+
const requestId = require_shared.resolveRequestId(this.context, props.requestId);
|
|
21
|
+
const path = require_shared.parsePath(props.path);
|
|
22
|
+
const xfp = require_shared.normalizeXfp(props.xfp);
|
|
23
|
+
if (props.signData.length === 0) throw new require_shared.EraSdkError("invalid-props", "signData must not be empty");
|
|
24
|
+
const entries = [
|
|
25
|
+
[1, require_shared.cbTag(37, require_shared.cbBytes(require_shared.utf8Encode(require_shared.uuidStringify(requestId))))],
|
|
26
|
+
[2, require_shared.cbBytes(props.signData)],
|
|
27
|
+
[3, require_shared.cbUint(props.dataType ?? TonDataType.transaction)],
|
|
28
|
+
[4, require_shared.keypath304(path, xfp)]
|
|
29
|
+
];
|
|
30
|
+
if (props.address !== void 0) entries.push([5, require_shared.cbText(props.address)]);
|
|
31
|
+
entries.push([6, require_shared.cbText(props.origin ?? this.context.origin)]);
|
|
32
|
+
const ur = new require_shared.Ur("ton-sign-request", require_shared.cborEncode(require_shared.cbMap(entries)));
|
|
33
|
+
return require_shared.makeSignRequest({
|
|
34
|
+
ur,
|
|
35
|
+
requestId,
|
|
36
|
+
replyTypes: REPLY_TYPES,
|
|
37
|
+
context: this.context,
|
|
38
|
+
parse: (reply) => parseTonSignature(reply, requestId)
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** Parse a `ton-signature` standalone. Prefer `SignRequest.scanner().parse()`. */
|
|
42
|
+
parseSignature(input, expect) {
|
|
43
|
+
return parseTonSignature(require_shared.toUr(input), expect?.requestId === void 0 ? void 0 : require_shared.normalizeRequestId(expect.requestId));
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
TonChain.DataType = TonDataType;
|
|
47
|
+
function parseTonSignature(ur, expectedRequestId) {
|
|
48
|
+
require_shared.requireUrType(ur, [...REPLY_TYPES], "ton-signature");
|
|
49
|
+
const map = require_shared.requireReplyMap(ur, "ton-signature");
|
|
50
|
+
const echoedValue = require_shared.mapGet(map, 1);
|
|
51
|
+
const echoed = echoedValue === void 0 ? void 0 : require_shared.stripTags(echoedValue);
|
|
52
|
+
if (echoed?.kind !== "bytes") throw new require_shared.EraSdkError("malformed-reply", "ton-signature does not echo the request id (key 1)");
|
|
53
|
+
const requestId = normalizeEchoedId(echoed.value);
|
|
54
|
+
if (expectedRequestId !== void 0) {
|
|
55
|
+
if (requestId === null || !require_shared.equalBytes(requestId, expectedRequestId)) throw new require_shared.EraSdkError("request-id-mismatch", "ton-signature echoes a different request id — it answers another sign request, not this one");
|
|
56
|
+
}
|
|
57
|
+
const sigValue = require_shared.mapGet(map, 2);
|
|
58
|
+
const sig = sigValue === void 0 ? void 0 : require_shared.stripTags(sigValue);
|
|
59
|
+
if (sig?.kind !== "bytes") throw new require_shared.EraSdkError("malformed-reply", "ton-signature is missing the signature (key 2)");
|
|
60
|
+
if (sig.value.length !== 64) throw new require_shared.EraSdkError("malformed-reply", `ton-signature signature is ${sig.value.length} bytes, expected 64`);
|
|
61
|
+
return {
|
|
62
|
+
requestId: requestId ?? /* @__PURE__ */ new Uint8Array(16),
|
|
63
|
+
signature: sig.value
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** ASCII-UUID-string bytes (36) or raw binary (16) → 16-byte id; null if neither. */
|
|
67
|
+
function normalizeEchoedId(echoed) {
|
|
68
|
+
if (echoed.length === 16) return echoed;
|
|
69
|
+
if (echoed.length === 36) {
|
|
70
|
+
let text = "";
|
|
71
|
+
for (const b of echoed) {
|
|
72
|
+
if (b > 127) return null;
|
|
73
|
+
text += String.fromCharCode(b);
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
return require_shared.normalizeRequestId(text);
|
|
77
|
+
} catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
Object.defineProperty(exports, "TonChain", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function() {
|
|
87
|
+
return TonChain;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
Object.defineProperty(exports, "TonDataType", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
get: function() {
|
|
93
|
+
return TonDataType;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=ton-DUJGXdGa.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ton-DUJGXdGa.cjs","names":["resolveContext","resolveRequestId","parsePath","normalizeXfp","EraSdkError","cbTag","cbBytes","utf8Encode","uuidStringify","cbUint","keypath304","cbText","UrValue","cborEncode","cbMap","makeSignRequest","toUr","normalizeRequestId","requireReplyMap","mapGet","stripTags","equalBytes"],"sources":["../src/chains/ton.ts"],"sourcesContent":["import { cborEncode } from '../cbor/encode';\nimport type { CborValue } from '../cbor/model';\nimport { cbBytes, cbMap, cbTag, cbText, cbUint, mapGet, stripTags } from '../cbor/model';\nimport { equalBytes, utf8Encode } from '../core/bytes';\nimport { EraSdkError } from '../core/errors';\nimport { normalizeRequestId, uuidStringify } from '../core/rand';\nimport { keypath304, normalizeXfp, parsePath } from '../registry/keypath';\nimport type { Ur } from '../ur/ur';\nimport { Ur as UrValue } from '../ur/ur';\nimport type { ChainContext, EraConnectConfig, ExpectedReply, SignRequest } from './shared';\nimport {\n makeSignRequest,\n requireReplyMap,\n requireUrType,\n resolveContext,\n resolveRequestId,\n toUr,\n} from './shared';\n\n/** `ton-sign-request` dataType (CBOR key 3). */\nexport const TonDataType = {\n /** `signData` is a Bag-of-Cells; the device signs the ROOT CELL's representation hash. */\n transaction: 1,\n /**\n * TON Connect proof: the device signs\n * `sha256(0xFFFF || \"ton-connect\" || sha256(signData))`.\n */\n tonProof: 2,\n} as const;\nexport type TonDataType = (typeof TonDataType)[keyof typeof TonDataType];\n\nexport interface TonSignRequestProps {\n readonly requestId?: Uint8Array | string;\n /** BoC bytes (transaction) or the raw proof payload (tonProof). */\n readonly signData: Uint8Array;\n /** Defaults to `transaction`. */\n readonly dataType?: TonDataType;\n /** The account path, e.g. `m/44'/607'/0'` (V4R2 and V5R1 share it — the wallet-contract version affects only the address). */\n readonly path: string;\n readonly xfp: string | number;\n /** User-friendly bounceable address TEXT (`UQ…`/`EQ…`) — shown on the device. */\n readonly address?: string;\n readonly origin?: string;\n}\n\nexport interface TonSignatureResult {\n readonly requestId: Uint8Array;\n /** 64-byte Ed25519 signature over the digest for the request's dataType. */\n readonly signature: Uint8Array;\n}\n\nconst REPLY_TYPES = ['ton-signature'] as const;\n\nexport class TonChain {\n static readonly DataType = TonDataType;\n\n private readonly context: ChainContext;\n\n constructor(config?: EraConnectConfig) {\n this.context = resolveContext(config);\n }\n\n /** Build a `ton-sign-request` (7201). Reply: `ton-signature` (7202). */\n generateSignRequest(props: TonSignRequestProps): SignRequest<TonSignatureResult> {\n const requestId = resolveRequestId(this.context, props.requestId);\n const path = parsePath(props.path);\n const xfp = normalizeXfp(props.xfp);\n if (props.signData.length === 0) {\n throw new EraSdkError('invalid-props', 'signData must not be empty');\n }\n\n const entries: [number, CborValue][] = [\n // TON ecosystem quirk: the request id travels as the ASCII BYTES of the\n // hyphenated UUID string, wrapped in tag 37 (that is what Tonkeeper-\n // style integrations emit and what the device echoes back verbatim).\n [1, cbTag(37, cbBytes(utf8Encode(uuidStringify(requestId))))],\n [2, cbBytes(props.signData)],\n [3, cbUint(props.dataType ?? TonDataType.transaction)],\n [4, keypath304(path, xfp)],\n ];\n if (props.address !== undefined) entries.push([5, cbText(props.address)]);\n entries.push([6, cbText(props.origin ?? this.context.origin)]);\n\n const ur = new UrValue('ton-sign-request', cborEncode(cbMap(entries)));\n return makeSignRequest({\n ur,\n requestId,\n replyTypes: REPLY_TYPES,\n context: this.context,\n parse: (reply) => parseTonSignature(reply, requestId),\n });\n }\n\n /** Parse a `ton-signature` standalone. Prefer `SignRequest.scanner().parse()`. */\n parseSignature(input: Ur | string, expect?: ExpectedReply): TonSignatureResult {\n return parseTonSignature(\n toUr(input),\n expect?.requestId === undefined ? undefined : normalizeRequestId(expect.requestId),\n );\n }\n}\n\nfunction parseTonSignature(ur: Ur, expectedRequestId: Uint8Array | undefined): TonSignatureResult {\n requireUrType(ur, [...REPLY_TYPES], 'ton-signature');\n const map = requireReplyMap(ur, 'ton-signature');\n\n // The device echoes the request id BYTES verbatim (tag-37 wrapped). On this\n // chain those bytes are normally the ASCII of the UUID string; a bare\n // 16-byte binary echo is accepted too for forward compatibility.\n const echoedValue = mapGet(map, 1);\n const echoed = echoedValue === undefined ? undefined : stripTags(echoedValue);\n if (echoed?.kind !== 'bytes') {\n throw new EraSdkError('malformed-reply', 'ton-signature does not echo the request id (key 1)');\n }\n const requestId = normalizeEchoedId(echoed.value);\n if (expectedRequestId !== undefined) {\n if (requestId === null || !equalBytes(requestId, expectedRequestId)) {\n throw new EraSdkError(\n 'request-id-mismatch',\n 'ton-signature echoes a different request id — it answers another sign request, not this one',\n );\n }\n }\n\n const sigValue = mapGet(map, 2);\n const sig = sigValue === undefined ? undefined : stripTags(sigValue);\n if (sig?.kind !== 'bytes') {\n throw new EraSdkError('malformed-reply', 'ton-signature is missing the signature (key 2)');\n }\n if (sig.value.length !== 64) {\n throw new EraSdkError(\n 'malformed-reply',\n `ton-signature signature is ${sig.value.length} bytes, expected 64`,\n );\n }\n return { requestId: requestId ?? new Uint8Array(16), signature: sig.value };\n}\n\n/** ASCII-UUID-string bytes (36) or raw binary (16) → 16-byte id; null if neither. */\nfunction normalizeEchoedId(echoed: Uint8Array): Uint8Array | null {\n if (echoed.length === 16) return echoed;\n if (echoed.length === 36) {\n let text = '';\n for (const b of echoed) {\n if (b > 0x7f) return null;\n text += String.fromCharCode(b);\n }\n try {\n return normalizeRequestId(text);\n } catch {\n return null;\n }\n }\n return null;\n}\n"],"mappings":";;;AAoBA,MAAa,cAAc;;CAEzB,aAAa;;;;;CAKb,UAAU;AACZ;AAuBA,MAAM,cAAc,CAAC,eAAe;AAEpC,IAAa,WAAb,MAAsB;CAKpB,YAAY,QAA2B;EACrC,KAAK,UAAUA,eAAAA,eAAe,MAAM;CACtC;;CAGA,oBAAoB,OAA6D;EAC/E,MAAM,YAAYC,eAAAA,iBAAiB,KAAK,SAAS,MAAM,SAAS;EAChE,MAAM,OAAOC,eAAAA,UAAU,MAAM,IAAI;EACjC,MAAM,MAAMC,eAAAA,aAAa,MAAM,GAAG;EAClC,IAAI,MAAM,SAAS,WAAW,GAC5B,MAAM,IAAIC,eAAAA,YAAY,iBAAiB,4BAA4B;EAGrE,MAAM,UAAiC;GAIrC,CAAC,GAAGC,eAAAA,MAAM,IAAIC,eAAAA,QAAQC,eAAAA,WAAWC,eAAAA,cAAc,SAAS,CAAC,CAAC,CAAC,CAAC;GAC5D,CAAC,GAAGF,eAAAA,QAAQ,MAAM,QAAQ,CAAC;GAC3B,CAAC,GAAGG,eAAAA,OAAO,MAAM,YAAY,YAAY,WAAW,CAAC;GACrD,CAAC,GAAGC,eAAAA,WAAW,MAAM,GAAG,CAAC;EAC3B;EACA,IAAI,MAAM,YAAY,KAAA,GAAW,QAAQ,KAAK,CAAC,GAAGC,eAAAA,OAAO,MAAM,OAAO,CAAC,CAAC;EACxE,QAAQ,KAAK,CAAC,GAAGA,eAAAA,OAAO,MAAM,UAAU,KAAK,QAAQ,MAAM,CAAC,CAAC;EAE7D,MAAM,KAAK,IAAIC,eAAAA,GAAQ,oBAAoBC,eAAAA,WAAWC,eAAAA,MAAM,OAAO,CAAC,CAAC;EACrE,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AI,OAAO;CACjC,IAAI,OAAO,WAAW,IAAI;EACxB,IAAI,OAAO;EACX,KAAK,MAAM,KAAK,QAAQ;GACtB,IAAI,IAAI,KAAM,OAAO;GACrB,QAAQ,OAAO,aAAa,CAAC;EAC/B;EACA,IAAI;GACF,OAAOa,eAAAA,mBAAmB,IAAI;EAChC,QAAQ;GACN,OAAO;EACT;CACF;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { _ as Ur, a as SignRequest, i as ExpectedReply, r as EraConnectConfig } from "./shared-CI8zhQiE.cjs";
|
|
2
|
+
//#region src/chains/ton.d.ts
|
|
3
|
+
/** `ton-sign-request` dataType (CBOR key 3). */
|
|
4
|
+
declare const TonDataType: {
|
|
5
|
+
/** `signData` is a Bag-of-Cells; the device signs the ROOT CELL's representation hash. */
|
|
6
|
+
readonly transaction: 1;
|
|
7
|
+
/**
|
|
8
|
+
* TON Connect proof: the device signs
|
|
9
|
+
* `sha256(0xFFFF || "ton-connect" || sha256(signData))`.
|
|
10
|
+
*/
|
|
11
|
+
readonly tonProof: 2;
|
|
12
|
+
};
|
|
13
|
+
type TonDataType = (typeof TonDataType)[keyof typeof TonDataType];
|
|
14
|
+
interface TonSignRequestProps {
|
|
15
|
+
readonly requestId?: Uint8Array | string;
|
|
16
|
+
/** BoC bytes (transaction) or the raw proof payload (tonProof). */
|
|
17
|
+
readonly signData: Uint8Array;
|
|
18
|
+
/** Defaults to `transaction`. */
|
|
19
|
+
readonly dataType?: TonDataType;
|
|
20
|
+
/** The account path, e.g. `m/44'/607'/0'` (V4R2 and V5R1 share it — the wallet-contract version affects only the address). */
|
|
21
|
+
readonly path: string;
|
|
22
|
+
readonly xfp: string | number;
|
|
23
|
+
/** User-friendly bounceable address TEXT (`UQ…`/`EQ…`) — shown on the device. */
|
|
24
|
+
readonly address?: string;
|
|
25
|
+
readonly origin?: string;
|
|
26
|
+
}
|
|
27
|
+
interface TonSignatureResult {
|
|
28
|
+
readonly requestId: Uint8Array;
|
|
29
|
+
/** 64-byte Ed25519 signature over the digest for the request's dataType. */
|
|
30
|
+
readonly signature: Uint8Array;
|
|
31
|
+
}
|
|
32
|
+
declare class TonChain {
|
|
33
|
+
static readonly DataType: {
|
|
34
|
+
/** `signData` is a Bag-of-Cells; the device signs the ROOT CELL's representation hash. */
|
|
35
|
+
readonly transaction: 1;
|
|
36
|
+
/**
|
|
37
|
+
* TON Connect proof: the device signs
|
|
38
|
+
* `sha256(0xFFFF || "ton-connect" || sha256(signData))`.
|
|
39
|
+
*/
|
|
40
|
+
readonly tonProof: 2;
|
|
41
|
+
};
|
|
42
|
+
private readonly context;
|
|
43
|
+
constructor(config?: EraConnectConfig);
|
|
44
|
+
/** Build a `ton-sign-request` (7201). Reply: `ton-signature` (7202). */
|
|
45
|
+
generateSignRequest(props: TonSignRequestProps): SignRequest<TonSignatureResult>;
|
|
46
|
+
/** Parse a `ton-signature` standalone. Prefer `SignRequest.scanner().parse()`. */
|
|
47
|
+
parseSignature(input: Ur | string, expect?: ExpectedReply): TonSignatureResult;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { TonSignatureResult as i, TonDataType as n, TonSignRequestProps as r, TonChain as t };
|
|
51
|
+
//# sourceMappingURL=ton-DmeIvknN.d.cts.map
|
package/dist/ton.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_shared = require("./shared-nISrEktU.cjs");
|
|
3
|
+
const require_ton = require("./ton-DUJGXdGa.cjs");
|
|
4
|
+
exports.AnimatedUr = require_shared.AnimatedUr;
|
|
5
|
+
exports.EraSdkError = require_shared.EraSdkError;
|
|
6
|
+
exports.TonChain = require_ton.TonChain;
|
|
7
|
+
exports.TonDataType = require_ton.TonDataType;
|
|
8
|
+
exports.TypedUrScanner = require_shared.TypedUrScanner;
|
|
9
|
+
exports.Ur = require_shared.Ur;
|
|
10
|
+
exports.UrScanner = require_shared.UrScanner;
|
package/dist/ton.d.cts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { _ as Ur, a as SignRequest, c as TypedUrScanner, d as EraErrorCode, f as EraSdkError, i as ExpectedReply, l as UrScanner, p as AnimatedUr, r as EraConnectConfig } from "./shared-CI8zhQiE.cjs";
|
|
2
|
+
import { i as TonSignatureResult, n as TonDataType, r as TonSignRequestProps, t as TonChain } from "./ton-DmeIvknN.cjs";
|
|
3
|
+
export { AnimatedUr, type EraConnectConfig, type EraErrorCode, EraSdkError, type ExpectedReply, type SignRequest, TonChain, TonDataType, type TonSignRequestProps, type TonSignatureResult, TypedUrScanner, Ur, UrScanner };
|
package/dist/ton.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { _ as Ur, a as SignRequest, c as TypedUrScanner, d as EraErrorCode, f as EraSdkError, i as ExpectedReply, l as UrScanner, p as AnimatedUr, r as EraConnectConfig } from "./shared-CI8zhQiE.js";
|
|
2
|
+
import { i as TonSignatureResult, n as TonDataType, r as TonSignRequestProps, t as TonChain } from "./ton-C0UP-cf_.js";
|
|
3
|
+
export { AnimatedUr, type EraConnectConfig, type EraErrorCode, EraSdkError, type ExpectedReply, type SignRequest, TonChain, TonDataType, type TonSignRequestProps, type TonSignatureResult, TypedUrScanner, Ur, UrScanner };
|
package/dist/ton.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Z as EraSdkError, _ as Ur, d as UrScanner, f as AnimatedUr, u as TypedUrScanner } from "./shared-B8Wc7ViU.js";
|
|
2
|
+
import { n as TonDataType, t as TonChain } from "./ton-5Uvi5ifg.js";
|
|
3
|
+
export { AnimatedUr, EraSdkError, TonChain, TonDataType, TypedUrScanner, Ur, UrScanner };
|