xpi-ts 0.2.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/LICENSE +21 -0
- package/README.md +516 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/lib/bitcore/address.d.ts +66 -0
- package/dist/lib/bitcore/address.d.ts.map +1 -0
- package/dist/lib/bitcore/address.js +407 -0
- package/dist/lib/bitcore/block/block.d.ts +57 -0
- package/dist/lib/bitcore/block/block.d.ts.map +1 -0
- package/dist/lib/bitcore/block/block.js +233 -0
- package/dist/lib/bitcore/block/blockheader.d.ts +82 -0
- package/dist/lib/bitcore/block/blockheader.d.ts.map +1 -0
- package/dist/lib/bitcore/block/blockheader.js +323 -0
- package/dist/lib/bitcore/block/index.d.ts +5 -0
- package/dist/lib/bitcore/block/index.d.ts.map +1 -0
- package/dist/lib/bitcore/block/index.js +2 -0
- package/dist/lib/bitcore/chunk.d.ts +22 -0
- package/dist/lib/bitcore/chunk.d.ts.map +1 -0
- package/dist/lib/bitcore/chunk.js +46 -0
- package/dist/lib/bitcore/crypto/bn.d.ts +53 -0
- package/dist/lib/bitcore/crypto/bn.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/bn.js +238 -0
- package/dist/lib/bitcore/crypto/ecdsa.d.ts +46 -0
- package/dist/lib/bitcore/crypto/ecdsa.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/ecdsa.js +247 -0
- package/dist/lib/bitcore/crypto/hash.d.ts +16 -0
- package/dist/lib/bitcore/crypto/hash.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/hash.js +87 -0
- package/dist/lib/bitcore/crypto/index.d.ts +9 -0
- package/dist/lib/bitcore/crypto/index.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/index.js +8 -0
- package/dist/lib/bitcore/crypto/musig2.d.ts +40 -0
- package/dist/lib/bitcore/crypto/musig2.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/musig2.js +236 -0
- package/dist/lib/bitcore/crypto/point.d.ts +20 -0
- package/dist/lib/bitcore/crypto/point.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/point.js +133 -0
- package/dist/lib/bitcore/crypto/random.d.ts +7 -0
- package/dist/lib/bitcore/crypto/random.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/random.js +30 -0
- package/dist/lib/bitcore/crypto/schnorr.d.ts +40 -0
- package/dist/lib/bitcore/crypto/schnorr.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/schnorr.js +185 -0
- package/dist/lib/bitcore/crypto/signature.d.ts +53 -0
- package/dist/lib/bitcore/crypto/signature.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/signature.js +300 -0
- package/dist/lib/bitcore/crypto/sigtype.d.ts +5 -0
- package/dist/lib/bitcore/crypto/sigtype.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/sigtype.js +18 -0
- package/dist/lib/bitcore/encoding/base58.d.ts +16 -0
- package/dist/lib/bitcore/encoding/base58.d.ts.map +1 -0
- package/dist/lib/bitcore/encoding/base58.js +55 -0
- package/dist/lib/bitcore/encoding/base58check.d.ts +9 -0
- package/dist/lib/bitcore/encoding/base58check.d.ts.map +1 -0
- package/dist/lib/bitcore/encoding/base58check.js +82 -0
- package/dist/lib/bitcore/encoding/bufferreader.d.ts +34 -0
- package/dist/lib/bitcore/encoding/bufferreader.d.ts.map +1 -0
- package/dist/lib/bitcore/encoding/bufferreader.js +198 -0
- package/dist/lib/bitcore/encoding/bufferwriter.d.ts +36 -0
- package/dist/lib/bitcore/encoding/bufferwriter.d.ts.map +1 -0
- package/dist/lib/bitcore/encoding/bufferwriter.js +189 -0
- package/dist/lib/bitcore/encoding/varint.d.ts +20 -0
- package/dist/lib/bitcore/encoding/varint.d.ts.map +1 -0
- package/dist/lib/bitcore/encoding/varint.js +61 -0
- package/dist/lib/bitcore/errors.d.ts +28 -0
- package/dist/lib/bitcore/errors.d.ts.map +1 -0
- package/dist/lib/bitcore/errors.js +325 -0
- package/dist/lib/bitcore/hdprivatekey.d.ts +78 -0
- package/dist/lib/bitcore/hdprivatekey.d.ts.map +1 -0
- package/dist/lib/bitcore/hdprivatekey.js +381 -0
- package/dist/lib/bitcore/hdpublickey.d.ts +98 -0
- package/dist/lib/bitcore/hdpublickey.d.ts.map +1 -0
- package/dist/lib/bitcore/hdpublickey.js +416 -0
- package/dist/lib/bitcore/index.d.ts +60 -0
- package/dist/lib/bitcore/index.d.ts.map +1 -0
- package/dist/lib/bitcore/index.js +44 -0
- package/dist/lib/bitcore/message.d.ts +23 -0
- package/dist/lib/bitcore/message.d.ts.map +1 -0
- package/dist/lib/bitcore/message.js +112 -0
- package/dist/lib/bitcore/mnemonic/errors.d.ts +7 -0
- package/dist/lib/bitcore/mnemonic/errors.d.ts.map +1 -0
- package/dist/lib/bitcore/mnemonic/errors.js +20 -0
- package/dist/lib/bitcore/mnemonic/index.d.ts +5 -0
- package/dist/lib/bitcore/mnemonic/index.d.ts.map +1 -0
- package/dist/lib/bitcore/mnemonic/index.js +4 -0
- package/dist/lib/bitcore/mnemonic/mnemonic.d.ts +23 -0
- package/dist/lib/bitcore/mnemonic/mnemonic.d.ts.map +1 -0
- package/dist/lib/bitcore/mnemonic/mnemonic.js +164 -0
- package/dist/lib/bitcore/mnemonic/pbkdf2.d.ts +2 -0
- package/dist/lib/bitcore/mnemonic/pbkdf2.d.ts.map +1 -0
- package/dist/lib/bitcore/mnemonic/pbkdf2.js +25 -0
- package/dist/lib/bitcore/mnemonic/words/english.d.ts +2 -0
- package/dist/lib/bitcore/mnemonic/words/english.d.ts.map +1 -0
- package/dist/lib/bitcore/mnemonic/words/english.js +2050 -0
- package/dist/lib/bitcore/mnemonic/words/index.d.ts +4 -0
- package/dist/lib/bitcore/mnemonic/words/index.d.ts.map +1 -0
- package/dist/lib/bitcore/mnemonic/words/index.js +4 -0
- package/dist/lib/bitcore/musig2/index.d.ts +3 -0
- package/dist/lib/bitcore/musig2/index.d.ts.map +1 -0
- package/dist/lib/bitcore/musig2/index.js +2 -0
- package/dist/lib/bitcore/musig2/session.d.ts +79 -0
- package/dist/lib/bitcore/musig2/session.d.ts.map +1 -0
- package/dist/lib/bitcore/musig2/session.js +346 -0
- package/dist/lib/bitcore/musig2/signer.d.ts +61 -0
- package/dist/lib/bitcore/musig2/signer.d.ts.map +1 -0
- package/dist/lib/bitcore/musig2/signer.js +146 -0
- package/dist/lib/bitcore/networks.d.ts +53 -0
- package/dist/lib/bitcore/networks.d.ts.map +1 -0
- package/dist/lib/bitcore/networks.js +150 -0
- package/dist/lib/bitcore/opcode.d.ts +250 -0
- package/dist/lib/bitcore/opcode.d.ts.map +1 -0
- package/dist/lib/bitcore/opcode.js +270 -0
- package/dist/lib/bitcore/privatekey.d.ts +56 -0
- package/dist/lib/bitcore/privatekey.d.ts.map +1 -0
- package/dist/lib/bitcore/privatekey.js +237 -0
- package/dist/lib/bitcore/publickey.d.ts +59 -0
- package/dist/lib/bitcore/publickey.d.ts.map +1 -0
- package/dist/lib/bitcore/publickey.js +263 -0
- package/dist/lib/bitcore/script/interpreter.d.ts +98 -0
- package/dist/lib/bitcore/script/interpreter.d.ts.map +1 -0
- package/dist/lib/bitcore/script/interpreter.js +1704 -0
- package/dist/lib/bitcore/script.d.ts +111 -0
- package/dist/lib/bitcore/script.d.ts.map +1 -0
- package/dist/lib/bitcore/script.js +1112 -0
- package/dist/lib/bitcore/taproot/musig2.d.ts +29 -0
- package/dist/lib/bitcore/taproot/musig2.d.ts.map +1 -0
- package/dist/lib/bitcore/taproot/musig2.js +104 -0
- package/dist/lib/bitcore/taproot/nft.d.ts +164 -0
- package/dist/lib/bitcore/taproot/nft.d.ts.map +1 -0
- package/dist/lib/bitcore/taproot/nft.js +407 -0
- package/dist/lib/bitcore/taproot.d.ts +65 -0
- package/dist/lib/bitcore/taproot.d.ts.map +1 -0
- package/dist/lib/bitcore/taproot.js +288 -0
- package/dist/lib/bitcore/transaction/index.d.ts +12 -0
- package/dist/lib/bitcore/transaction/index.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/index.js +6 -0
- package/dist/lib/bitcore/transaction/input.d.ts +202 -0
- package/dist/lib/bitcore/transaction/input.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/input.js +911 -0
- package/dist/lib/bitcore/transaction/output.d.ts +48 -0
- package/dist/lib/bitcore/transaction/output.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/output.js +231 -0
- package/dist/lib/bitcore/transaction/sighash.d.ts +32 -0
- package/dist/lib/bitcore/transaction/sighash.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/sighash.js +335 -0
- package/dist/lib/bitcore/transaction/signature.d.ts +36 -0
- package/dist/lib/bitcore/transaction/signature.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/signature.js +130 -0
- package/dist/lib/bitcore/transaction/transaction.d.ts +164 -0
- package/dist/lib/bitcore/transaction/transaction.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/transaction.js +1016 -0
- package/dist/lib/bitcore/transaction/unspentoutput.d.ts +58 -0
- package/dist/lib/bitcore/transaction/unspentoutput.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/unspentoutput.js +167 -0
- package/dist/lib/bitcore/unit.d.ts +44 -0
- package/dist/lib/bitcore/unit.d.ts.map +1 -0
- package/dist/lib/bitcore/unit.js +106 -0
- package/dist/lib/bitcore/uri.d.ts +29 -0
- package/dist/lib/bitcore/uri.d.ts.map +1 -0
- package/dist/lib/bitcore/uri.js +163 -0
- package/dist/lib/bitcore/util/base32.d.ts +5 -0
- package/dist/lib/bitcore/util/base32.d.ts.map +1 -0
- package/dist/lib/bitcore/util/base32.js +58 -0
- package/dist/lib/bitcore/util/buffer.d.ts +18 -0
- package/dist/lib/bitcore/util/buffer.d.ts.map +1 -0
- package/dist/lib/bitcore/util/buffer.js +76 -0
- package/dist/lib/bitcore/util/convertBits.d.ts +2 -0
- package/dist/lib/bitcore/util/convertBits.d.ts.map +1 -0
- package/dist/lib/bitcore/util/convertBits.js +26 -0
- package/dist/lib/bitcore/util/js.d.ts +9 -0
- package/dist/lib/bitcore/util/js.d.ts.map +1 -0
- package/dist/lib/bitcore/util/js.js +45 -0
- package/dist/lib/bitcore/util/preconditions.d.ts +6 -0
- package/dist/lib/bitcore/util/preconditions.d.ts.map +1 -0
- package/dist/lib/bitcore/util/preconditions.js +31 -0
- package/dist/lib/bitcore/util.d.ts +14 -0
- package/dist/lib/bitcore/util.d.ts.map +1 -0
- package/dist/lib/bitcore/util.js +13 -0
- package/dist/lib/bitcore/xaddress.d.ts +45 -0
- package/dist/lib/bitcore/xaddress.d.ts.map +1 -0
- package/dist/lib/bitcore/xaddress.js +279 -0
- package/dist/lib/rank/api.d.ts +75 -0
- package/dist/lib/rank/api.d.ts.map +1 -0
- package/dist/lib/rank/api.js +4 -0
- package/dist/lib/rank/index.d.ts +127 -0
- package/dist/lib/rank/index.d.ts.map +1 -0
- package/dist/lib/rank/index.js +421 -0
- package/dist/lib/rank/opcode.d.ts +23 -0
- package/dist/lib/rank/opcode.d.ts.map +1 -0
- package/dist/lib/rank/opcode.js +23 -0
- package/dist/lib/rank/script.d.ts +2 -0
- package/dist/lib/rank/script.d.ts.map +1 -0
- package/dist/lib/rank/script.js +7 -0
- package/dist/lib/rank/transaction.d.ts +3 -0
- package/dist/lib/rank/transaction.d.ts.map +1 -0
- package/dist/lib/rank/transaction.js +12 -0
- package/dist/lib/rpc.d.ts +136 -0
- package/dist/lib/rpc.d.ts.map +1 -0
- package/dist/lib/rpc.js +62 -0
- package/dist/utils/constants.d.ts +18 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +20 -0
- package/dist/utils/env.d.ts +3 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/utils/env.js +8 -0
- package/dist/utils/string.d.ts +11 -0
- package/dist/utils/string.d.ts.map +1 -0
- package/dist/utils/string.js +47 -0
- package/dist/utils/types.d.ts +2 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +1 -0
- package/dist/utils/wallet.d.ts +12 -0
- package/dist/utils/wallet.d.ts.map +1 -0
- package/dist/utils/wallet.js +28 -0
- package/package.json +91 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import OpCode from './opcode.js';
|
|
2
|
+
export type ScriptChunkLokadUTF8 = 'RANK' | 'RNKC';
|
|
3
|
+
export type ScriptChunkPlatformUTF8 = 'lotusia' | 'twitter';
|
|
4
|
+
export type ScriptChunkSentimentUTF8 = 'positive' | 'negative' | 'neutral';
|
|
5
|
+
export type ScriptChunkLokadMap = Map<number, ScriptChunkLokadUTF8>;
|
|
6
|
+
export type ScriptChunkPlatformMap = Map<number, ScriptChunkPlatformUTF8>;
|
|
7
|
+
export type ScriptChunkSentimentMap = Map<number, ScriptChunkSentimentUTF8>;
|
|
8
|
+
export type ScriptChunkField = 'sentiment' | 'platform' | 'profileId' | 'postId' | 'comment' | 'postHash' | 'instanceId';
|
|
9
|
+
export type ScriptChunk = {
|
|
10
|
+
offset: number | null;
|
|
11
|
+
len: number | null;
|
|
12
|
+
map?: ScriptChunkLokadMap | ScriptChunkPlatformMap | ScriptChunkSentimentMap;
|
|
13
|
+
};
|
|
14
|
+
export type ScriptChunksRNKC = {
|
|
15
|
+
[name in Exclude<ScriptChunkField, 'sentiment' | 'postHash' | 'instanceId'>]: ScriptChunk;
|
|
16
|
+
};
|
|
17
|
+
export type ScriptChunksRANK = {
|
|
18
|
+
[name in Exclude<ScriptChunkField, 'comment' | 'postId' | 'postHash' | 'instanceId'>]: ScriptChunk;
|
|
19
|
+
};
|
|
20
|
+
export type ScriptChunksOptionalRANK = {
|
|
21
|
+
[name in Extract<ScriptChunkField, 'postId' | 'postHash' | 'instanceId'>]: ScriptChunk;
|
|
22
|
+
};
|
|
23
|
+
export type TransactionOutputRANK = {
|
|
24
|
+
sentiment: ScriptChunkSentimentUTF8;
|
|
25
|
+
platform: ScriptChunkPlatformUTF8;
|
|
26
|
+
profileId: string;
|
|
27
|
+
postId?: string;
|
|
28
|
+
};
|
|
29
|
+
export type TransactionOutputRNKC = {
|
|
30
|
+
data: Uint8Array;
|
|
31
|
+
feeRate: number;
|
|
32
|
+
inReplyToPlatform: ScriptChunkPlatformUTF8;
|
|
33
|
+
inReplyToProfileId?: string;
|
|
34
|
+
inReplyToPostId?: string;
|
|
35
|
+
};
|
|
36
|
+
export type Transaction = {
|
|
37
|
+
txid: string;
|
|
38
|
+
outIdx: number;
|
|
39
|
+
sats: bigint;
|
|
40
|
+
firstSeen: bigint;
|
|
41
|
+
scriptPayload: string;
|
|
42
|
+
instanceId?: string;
|
|
43
|
+
height?: number;
|
|
44
|
+
timestamp?: bigint;
|
|
45
|
+
};
|
|
46
|
+
export type TransactionRANK = TransactionOutputRANK & Transaction;
|
|
47
|
+
export type TransactionRNKC = TransactionOutputRNKC & Transaction;
|
|
48
|
+
export type TargetEntity = {
|
|
49
|
+
id: string;
|
|
50
|
+
platform: string;
|
|
51
|
+
ranking: bigint;
|
|
52
|
+
ranks: Omit<TransactionRANK, 'profileId' | 'platform'>[];
|
|
53
|
+
comments: Omit<TransactionRNKC, 'inReplyToProfileId' | 'inReplyToPlatform'>[];
|
|
54
|
+
satsPositive: bigint;
|
|
55
|
+
satsNegative: bigint;
|
|
56
|
+
votesPositive: number;
|
|
57
|
+
votesNegative: number;
|
|
58
|
+
};
|
|
59
|
+
export type ProfileMap = Map<string, Profile>;
|
|
60
|
+
export type PostMap = Map<string, Post>;
|
|
61
|
+
export type Profile = TargetEntity & {
|
|
62
|
+
posts?: PostMap;
|
|
63
|
+
};
|
|
64
|
+
export type Post = TargetEntity & {
|
|
65
|
+
profileId: string;
|
|
66
|
+
data?: Uint8Array;
|
|
67
|
+
};
|
|
68
|
+
export type PlatformParameters = {
|
|
69
|
+
profileId: {
|
|
70
|
+
len: number;
|
|
71
|
+
regex: RegExp;
|
|
72
|
+
};
|
|
73
|
+
postId: {
|
|
74
|
+
len: number;
|
|
75
|
+
regex: RegExp;
|
|
76
|
+
type: 'BigInt' | 'Number' | 'String';
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
export declare const LOKAD_PREFIX_RANK = 1380011595;
|
|
80
|
+
export declare const LOKAD_PREFIX_RNKC = 1380862787;
|
|
81
|
+
export declare const SCRIPT_CHUNK_LOKAD: ScriptChunkLokadMap;
|
|
82
|
+
export declare const RANK_SENTIMENT_NEUTRAL = OpCode.OP_16;
|
|
83
|
+
export declare const RANK_SENTIMENT_POSITIVE = OpCode.OP_1;
|
|
84
|
+
export declare const RANK_SENTIMENT_NEGATIVE = OpCode.OP_0;
|
|
85
|
+
export declare const SCRIPT_CHUNK_SENTIMENT: ScriptChunkSentimentMap;
|
|
86
|
+
export declare const RANK_SENTIMENT_OP_CODES: Map<ScriptChunkSentimentUTF8, string>;
|
|
87
|
+
export declare const SCRIPT_CHUNK_PLATFORM: ScriptChunkPlatformMap;
|
|
88
|
+
export declare const ScriptChunksRNKCMap: Map<keyof ScriptChunksRNKC, ScriptChunk>;
|
|
89
|
+
export declare const RANK_SCRIPT_REQUIRED_LENGTH = 10;
|
|
90
|
+
export declare const ScriptChunksRANKMap: Map<keyof ScriptChunksRANK, ScriptChunk>;
|
|
91
|
+
export declare const ScriptChunksOptionalRANKMap: Map<keyof ScriptChunksOptionalRANK, ScriptChunk>;
|
|
92
|
+
export declare const PlatformConfiguration: Map<ScriptChunkPlatformUTF8, PlatformParameters>;
|
|
93
|
+
export declare function toProfileIdBuf(platform: ScriptChunkPlatformUTF8, profileId: string): Buffer | null;
|
|
94
|
+
export declare function toProfileIdUTF8(profileIdBuf: Buffer): string;
|
|
95
|
+
export declare function toPostIdBuf(platform: ScriptChunkPlatformUTF8, postId: string): Buffer | undefined;
|
|
96
|
+
export declare function toPlatformBuf(platform: ScriptChunkPlatformUTF8): Buffer | undefined;
|
|
97
|
+
export declare function toPlatformUTF8(platformBuf: Buffer): ScriptChunkPlatformUTF8 | undefined;
|
|
98
|
+
export declare function toSentimentOpCode(sentiment: ScriptChunkSentimentUTF8): string | undefined;
|
|
99
|
+
export declare function toSentimentUTF8(sentimentBuf: Buffer): ScriptChunkSentimentUTF8 | undefined;
|
|
100
|
+
export declare function toCommentUTF8(commentBuf: Buffer | Uint8Array): string | undefined;
|
|
101
|
+
export declare function toScriptRANK(sentiment: ScriptChunkSentimentUTF8, platform: ScriptChunkPlatformUTF8, profileId: string, postId?: string): Buffer;
|
|
102
|
+
export declare function toScriptRNKC({ platform, profileId, postId, comment, }: {
|
|
103
|
+
platform: ScriptChunkPlatformUTF8;
|
|
104
|
+
profileId: string;
|
|
105
|
+
postId?: string;
|
|
106
|
+
comment: string;
|
|
107
|
+
}): Buffer[];
|
|
108
|
+
export declare class ScriptProcessor {
|
|
109
|
+
private chunks;
|
|
110
|
+
private script;
|
|
111
|
+
private supplementalScripts;
|
|
112
|
+
constructor(script: Buffer);
|
|
113
|
+
addScript(script: string | Buffer): boolean;
|
|
114
|
+
get lokadType(): ScriptChunkLokadUTF8 | undefined;
|
|
115
|
+
private processLokad;
|
|
116
|
+
private processSentiment;
|
|
117
|
+
private processPlatform;
|
|
118
|
+
private processProfileId;
|
|
119
|
+
private processPostId;
|
|
120
|
+
private processComment;
|
|
121
|
+
processScriptRANK(): TransactionOutputRANK | null;
|
|
122
|
+
processScriptRNKC(burnedSats: number | bigint, options?: {
|
|
123
|
+
minDataLength: number;
|
|
124
|
+
minFeeRate: number;
|
|
125
|
+
}): TransactionOutputRNKC | null;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/rank/index.ts"],"names":[],"mappings":"AAWA,OAAO,MAAM,MAAM,aAAa,CAAA;AAGhC,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,MAAM,CAAA;AAClD,MAAM,MAAM,uBAAuB,GAAG,SAAS,GAAG,SAAS,CAAA;AAC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AAS,IAAI,oBAAoB,GAAG,SAAS,CAEhD;IAKD,OAAO,CAAC,YAAY;IAcpB,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,eAAe;IAoBvB,OAAO,CAAC,gBAAgB;IAsCxB,OAAO,CAAC,aAAa;IA0CrB,OAAO,CAAC,cAAc;IA2BtB,iBAAiB,IAAI,qBAAqB,GAAG,IAAI;IAsCjD,iBAAiB,CACf,UAAU,EAAE,MAAM,GAAG,MAAM,EAC3B,OAAO,CAAC,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GACtD,qBAAqB,GAAG,IAAI;CA4DhC"}
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import { MAX_OP_RETURN_DATA, RNKC_MIN_DATA_LENGTH, RNKC_MIN_FEE_RATE, } from '../../utils/constants.js';
|
|
2
|
+
import { toHex } from '../../utils/string.js';
|
|
3
|
+
import OpCode from './opcode.js';
|
|
4
|
+
import { isOpReturn } from './script.js';
|
|
5
|
+
export const LOKAD_PREFIX_RANK = 0x52414e4b;
|
|
6
|
+
export const LOKAD_PREFIX_RNKC = 0x524e4b43;
|
|
7
|
+
export const SCRIPT_CHUNK_LOKAD = new Map();
|
|
8
|
+
SCRIPT_CHUNK_LOKAD.set(LOKAD_PREFIX_RANK, 'RANK');
|
|
9
|
+
SCRIPT_CHUNK_LOKAD.set(LOKAD_PREFIX_RNKC, 'RNKC');
|
|
10
|
+
export const RANK_SENTIMENT_NEUTRAL = OpCode.OP_16;
|
|
11
|
+
export const RANK_SENTIMENT_POSITIVE = OpCode.OP_1;
|
|
12
|
+
export const RANK_SENTIMENT_NEGATIVE = OpCode.OP_0;
|
|
13
|
+
export const SCRIPT_CHUNK_SENTIMENT = new Map();
|
|
14
|
+
SCRIPT_CHUNK_SENTIMENT.set(RANK_SENTIMENT_NEUTRAL, 'neutral');
|
|
15
|
+
SCRIPT_CHUNK_SENTIMENT.set(RANK_SENTIMENT_POSITIVE, 'positive');
|
|
16
|
+
SCRIPT_CHUNK_SENTIMENT.set(RANK_SENTIMENT_NEGATIVE, 'negative');
|
|
17
|
+
export const RANK_SENTIMENT_OP_CODES = new Map();
|
|
18
|
+
RANK_SENTIMENT_OP_CODES.set('neutral', 'OP_16');
|
|
19
|
+
RANK_SENTIMENT_OP_CODES.set('positive', 'OP_1');
|
|
20
|
+
RANK_SENTIMENT_OP_CODES.set('negative', 'OP_0');
|
|
21
|
+
export const SCRIPT_CHUNK_PLATFORM = new Map();
|
|
22
|
+
SCRIPT_CHUNK_PLATFORM.set(0x00, 'lotusia');
|
|
23
|
+
SCRIPT_CHUNK_PLATFORM.set(0x01, 'twitter');
|
|
24
|
+
export const ScriptChunksRNKCMap = new Map();
|
|
25
|
+
ScriptChunksRNKCMap.set('platform', {
|
|
26
|
+
offset: 7,
|
|
27
|
+
len: 1,
|
|
28
|
+
map: SCRIPT_CHUNK_PLATFORM,
|
|
29
|
+
});
|
|
30
|
+
ScriptChunksRNKCMap.set('profileId', {
|
|
31
|
+
offset: 9,
|
|
32
|
+
len: null,
|
|
33
|
+
});
|
|
34
|
+
ScriptChunksRNKCMap.set('postId', {
|
|
35
|
+
offset: null,
|
|
36
|
+
len: null,
|
|
37
|
+
});
|
|
38
|
+
ScriptChunksRNKCMap.set('comment', {
|
|
39
|
+
offset: null,
|
|
40
|
+
len: null,
|
|
41
|
+
});
|
|
42
|
+
export const RANK_SCRIPT_REQUIRED_LENGTH = 10;
|
|
43
|
+
export const ScriptChunksRANKMap = new Map();
|
|
44
|
+
ScriptChunksRANKMap.set('sentiment', {
|
|
45
|
+
offset: 6,
|
|
46
|
+
len: 1,
|
|
47
|
+
map: SCRIPT_CHUNK_SENTIMENT,
|
|
48
|
+
});
|
|
49
|
+
ScriptChunksRANKMap.set('platform', {
|
|
50
|
+
offset: 8,
|
|
51
|
+
len: 1,
|
|
52
|
+
map: SCRIPT_CHUNK_PLATFORM,
|
|
53
|
+
});
|
|
54
|
+
ScriptChunksRANKMap.set('profileId', {
|
|
55
|
+
offset: 10,
|
|
56
|
+
len: null,
|
|
57
|
+
});
|
|
58
|
+
export const ScriptChunksOptionalRANKMap = new Map();
|
|
59
|
+
ScriptChunksOptionalRANKMap.set('postId', {
|
|
60
|
+
offset: null,
|
|
61
|
+
len: null,
|
|
62
|
+
});
|
|
63
|
+
ScriptChunksOptionalRANKMap.set('postHash', {
|
|
64
|
+
offset: null,
|
|
65
|
+
len: null,
|
|
66
|
+
});
|
|
67
|
+
ScriptChunksOptionalRANKMap.set('instanceId', {
|
|
68
|
+
offset: null,
|
|
69
|
+
len: null,
|
|
70
|
+
});
|
|
71
|
+
export const PlatformConfiguration = new Map();
|
|
72
|
+
PlatformConfiguration.set('lotusia', {
|
|
73
|
+
profileId: {
|
|
74
|
+
len: 20,
|
|
75
|
+
regex: /^[0-9a-fA-F]{40}$/,
|
|
76
|
+
},
|
|
77
|
+
postId: {
|
|
78
|
+
len: 32,
|
|
79
|
+
regex: /^[0-9a-f]{64}$/,
|
|
80
|
+
type: 'String',
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
PlatformConfiguration.set('twitter', {
|
|
84
|
+
profileId: {
|
|
85
|
+
len: 16,
|
|
86
|
+
regex: /^[a-z0-9_]{1,16}$/,
|
|
87
|
+
},
|
|
88
|
+
postId: {
|
|
89
|
+
len: 8,
|
|
90
|
+
regex: /^[0-9]+$/,
|
|
91
|
+
type: 'BigInt',
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
export function toProfileIdBuf(platform, profileId) {
|
|
95
|
+
const platformSpec = PlatformConfiguration.get(platform);
|
|
96
|
+
if (!platformSpec) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const profileIdSpec = platformSpec.profileId;
|
|
100
|
+
if (!profileIdSpec) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
if (profileIdSpec.regex && !profileIdSpec.regex.test(profileId)) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
const profileBuf = Buffer.alloc(profileIdSpec.len);
|
|
107
|
+
switch (platform) {
|
|
108
|
+
case 'lotusia': {
|
|
109
|
+
const profileIdHex = Buffer.from(profileId, 'hex');
|
|
110
|
+
profileBuf.write(profileId, profileIdSpec.len - profileIdHex.length, 'hex');
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
case 'twitter':
|
|
114
|
+
profileBuf.write(profileId, profileIdSpec.len - profileId.length, 'utf8');
|
|
115
|
+
break;
|
|
116
|
+
default:
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
return profileBuf;
|
|
120
|
+
}
|
|
121
|
+
export function toProfileIdUTF8(profileIdBuf) {
|
|
122
|
+
return new TextDecoder('utf-8').decode(profileIdBuf.filter(byte => byte != 0x00));
|
|
123
|
+
}
|
|
124
|
+
export function toPostIdBuf(platform, postId) {
|
|
125
|
+
switch (platform) {
|
|
126
|
+
case 'lotusia':
|
|
127
|
+
return Buffer.from(postId, 'hex');
|
|
128
|
+
case 'twitter':
|
|
129
|
+
return Buffer.from(BigInt(postId).toString(16), 'hex');
|
|
130
|
+
default:
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export function toPlatformBuf(platform) {
|
|
135
|
+
for (const [byte, platformName] of SCRIPT_CHUNK_PLATFORM) {
|
|
136
|
+
if (platformName == platform) {
|
|
137
|
+
return Buffer.from([byte]);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export function toPlatformUTF8(platformBuf) {
|
|
142
|
+
return SCRIPT_CHUNK_PLATFORM.get(platformBuf.readUint8());
|
|
143
|
+
}
|
|
144
|
+
export function toSentimentOpCode(sentiment) {
|
|
145
|
+
return RANK_SENTIMENT_OP_CODES.get(sentiment);
|
|
146
|
+
}
|
|
147
|
+
export function toSentimentUTF8(sentimentBuf) {
|
|
148
|
+
return SCRIPT_CHUNK_SENTIMENT.get(sentimentBuf.readUInt8());
|
|
149
|
+
}
|
|
150
|
+
export function toCommentUTF8(commentBuf) {
|
|
151
|
+
return new TextDecoder('utf-8').decode(commentBuf);
|
|
152
|
+
}
|
|
153
|
+
export function toScriptRANK(sentiment, platform, profileId, postId) {
|
|
154
|
+
if (!sentiment || !platform || !profileId) {
|
|
155
|
+
throw new Error('Must specify sentiment, platform, and profileId');
|
|
156
|
+
}
|
|
157
|
+
const platformSpec = PlatformConfiguration.get(platform);
|
|
158
|
+
if (!platformSpec || !platformSpec.profileId) {
|
|
159
|
+
throw new Error('No platform profileId specification defined');
|
|
160
|
+
}
|
|
161
|
+
const OP_RETURN = toHex(OpCode.OP_RETURN);
|
|
162
|
+
const LOKAD_PREFIX = toHex(LOKAD_PREFIX_RANK);
|
|
163
|
+
let script = OP_RETURN + toHex(4) + LOKAD_PREFIX;
|
|
164
|
+
switch (sentiment) {
|
|
165
|
+
case 'neutral':
|
|
166
|
+
script += toHex(RANK_SENTIMENT_NEUTRAL);
|
|
167
|
+
break;
|
|
168
|
+
case 'positive':
|
|
169
|
+
script += toHex(RANK_SENTIMENT_POSITIVE);
|
|
170
|
+
break;
|
|
171
|
+
case 'negative':
|
|
172
|
+
script += toHex(RANK_SENTIMENT_NEGATIVE);
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
script += toHex(1) + toHex(toPlatformBuf(platform));
|
|
176
|
+
script += toHex(platformSpec.profileId.len);
|
|
177
|
+
script += toHex(toProfileIdBuf(platform, profileId));
|
|
178
|
+
if (postId) {
|
|
179
|
+
if (!platformSpec.postId) {
|
|
180
|
+
throw new Error('Post ID provided, but no platform post specification defined');
|
|
181
|
+
}
|
|
182
|
+
script += toHex(platformSpec.postId.len);
|
|
183
|
+
script += toHex(toPostIdBuf(platform, postId));
|
|
184
|
+
}
|
|
185
|
+
return Buffer.from(script, 'hex');
|
|
186
|
+
}
|
|
187
|
+
export function toScriptRNKC({ platform, profileId, postId, comment, }) {
|
|
188
|
+
if (!platform || !profileId) {
|
|
189
|
+
throw new Error('Must specify platform and profileId');
|
|
190
|
+
}
|
|
191
|
+
const platformSpec = PlatformConfiguration.get(platform);
|
|
192
|
+
if (!platformSpec || !platformSpec.profileId) {
|
|
193
|
+
throw new Error('No platform profileId specification defined');
|
|
194
|
+
}
|
|
195
|
+
if (!platformSpec.profileId.regex.test(profileId)) {
|
|
196
|
+
throw new Error(`Invalid profileId: ${profileId}`);
|
|
197
|
+
}
|
|
198
|
+
if (postId && !platformSpec.postId.regex.test(postId)) {
|
|
199
|
+
throw new Error(`Invalid postId: ${postId}`);
|
|
200
|
+
}
|
|
201
|
+
const commentBuf = Buffer.from(comment, 'utf8');
|
|
202
|
+
if (commentBuf.length < 1 || commentBuf.length > MAX_OP_RETURN_DATA * 2) {
|
|
203
|
+
throw new Error(`Comment must be between 1 and ${MAX_OP_RETURN_DATA * 2} bytes`);
|
|
204
|
+
}
|
|
205
|
+
const scriptBufs = [];
|
|
206
|
+
const OP_RETURN = toHex(OpCode.OP_RETURN);
|
|
207
|
+
const OP_PUSHDATA1 = toHex(OpCode.OP_PUSHDATA1);
|
|
208
|
+
const LOKAD_PREFIX = toHex(LOKAD_PREFIX_RNKC);
|
|
209
|
+
let scriptRNKC = OP_RETURN + toHex(4) + LOKAD_PREFIX;
|
|
210
|
+
scriptRNKC += toHex(1) + toHex(toPlatformBuf(platform));
|
|
211
|
+
scriptRNKC += toHex(platformSpec.profileId.len);
|
|
212
|
+
scriptRNKC += toHex(toProfileIdBuf(platform, profileId));
|
|
213
|
+
if (postId) {
|
|
214
|
+
scriptRNKC += toHex(platformSpec.postId.len);
|
|
215
|
+
scriptRNKC += toHex(toPostIdBuf(platform, postId));
|
|
216
|
+
}
|
|
217
|
+
scriptBufs.push(Buffer.from(scriptRNKC, 'hex'));
|
|
218
|
+
const commentBuf1 = commentBuf.subarray(0, MAX_OP_RETURN_DATA);
|
|
219
|
+
let scriptComment = OP_RETURN + OP_PUSHDATA1;
|
|
220
|
+
scriptComment += toHex(commentBuf1.length);
|
|
221
|
+
scriptComment += toHex(commentBuf1);
|
|
222
|
+
scriptBufs.push(Buffer.from(scriptComment, 'hex'));
|
|
223
|
+
if (commentBuf.length > MAX_OP_RETURN_DATA) {
|
|
224
|
+
const commentBuf2 = commentBuf.subarray(MAX_OP_RETURN_DATA);
|
|
225
|
+
let scriptComment2 = OP_RETURN + OP_PUSHDATA1;
|
|
226
|
+
scriptComment2 += toHex(commentBuf2.length);
|
|
227
|
+
scriptComment2 += toHex(commentBuf2);
|
|
228
|
+
scriptBufs.push(Buffer.from(scriptComment2, 'hex'));
|
|
229
|
+
}
|
|
230
|
+
return scriptBufs;
|
|
231
|
+
}
|
|
232
|
+
export class ScriptProcessor {
|
|
233
|
+
chunks = null;
|
|
234
|
+
script;
|
|
235
|
+
supplementalScripts = [];
|
|
236
|
+
constructor(script) {
|
|
237
|
+
this.script = script;
|
|
238
|
+
switch (this.lokadType) {
|
|
239
|
+
case 'RANK':
|
|
240
|
+
this.chunks = ScriptChunksRANKMap;
|
|
241
|
+
break;
|
|
242
|
+
case 'RNKC':
|
|
243
|
+
this.chunks = ScriptChunksRNKCMap;
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
addScript(script) {
|
|
248
|
+
if (!(script instanceof Buffer)) {
|
|
249
|
+
script = Buffer.from(script, 'hex');
|
|
250
|
+
}
|
|
251
|
+
if (!isOpReturn(script)) {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
this.supplementalScripts.push(script);
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
get lokadType() {
|
|
258
|
+
return this.processLokad();
|
|
259
|
+
}
|
|
260
|
+
processLokad() {
|
|
261
|
+
const lokadBuf = this.script.subarray(2, 6);
|
|
262
|
+
const lokad = SCRIPT_CHUNK_LOKAD.get(lokadBuf.readUInt32BE(0));
|
|
263
|
+
if (!lokad) {
|
|
264
|
+
return undefined;
|
|
265
|
+
}
|
|
266
|
+
return lokad;
|
|
267
|
+
}
|
|
268
|
+
processSentiment() {
|
|
269
|
+
const chunk = this.chunks?.get('sentiment');
|
|
270
|
+
if (!chunk || chunk.offset === null) {
|
|
271
|
+
return undefined;
|
|
272
|
+
}
|
|
273
|
+
const sentimentBuf = this.script.subarray(chunk.offset, chunk.offset + chunk.len);
|
|
274
|
+
return SCRIPT_CHUNK_SENTIMENT.get(sentimentBuf.readUInt8());
|
|
275
|
+
}
|
|
276
|
+
processPlatform() {
|
|
277
|
+
const chunk = this.chunks?.get('platform');
|
|
278
|
+
if (!chunk || chunk.offset === null) {
|
|
279
|
+
return undefined;
|
|
280
|
+
}
|
|
281
|
+
const platformBuf = this.script.subarray(chunk.offset, chunk.offset + chunk.len);
|
|
282
|
+
const platform = SCRIPT_CHUNK_PLATFORM.get(platformBuf.readUInt8());
|
|
283
|
+
if (!platform) {
|
|
284
|
+
return undefined;
|
|
285
|
+
}
|
|
286
|
+
return platform;
|
|
287
|
+
}
|
|
288
|
+
processProfileId(platform) {
|
|
289
|
+
const chunk = this.chunks?.get('profileId');
|
|
290
|
+
if (!chunk || chunk.offset === null) {
|
|
291
|
+
return undefined;
|
|
292
|
+
}
|
|
293
|
+
const platformSpec = PlatformConfiguration.get(platform);
|
|
294
|
+
if (!platformSpec || !platformSpec.profileId) {
|
|
295
|
+
return undefined;
|
|
296
|
+
}
|
|
297
|
+
const profileIdSpec = platformSpec.profileId;
|
|
298
|
+
const profileIdBuf = this.script.subarray(chunk.offset, chunk.offset + profileIdSpec.len);
|
|
299
|
+
if (profileIdBuf.length < profileIdSpec.len) {
|
|
300
|
+
return undefined;
|
|
301
|
+
}
|
|
302
|
+
switch (platform) {
|
|
303
|
+
case 'lotusia':
|
|
304
|
+
return toHex(profileIdBuf);
|
|
305
|
+
case 'twitter':
|
|
306
|
+
return toProfileIdUTF8(profileIdBuf);
|
|
307
|
+
default:
|
|
308
|
+
return undefined;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
processPostId(platform) {
|
|
312
|
+
if (!platform) {
|
|
313
|
+
return undefined;
|
|
314
|
+
}
|
|
315
|
+
const platformSpec = PlatformConfiguration.get(platform);
|
|
316
|
+
if (!platformSpec || !platformSpec.postId || !platformSpec.profileId) {
|
|
317
|
+
return undefined;
|
|
318
|
+
}
|
|
319
|
+
const profileIdChunk = this.chunks?.get('profileId');
|
|
320
|
+
if (!profileIdChunk?.offset) {
|
|
321
|
+
return undefined;
|
|
322
|
+
}
|
|
323
|
+
const postIdSpec = platformSpec.postId;
|
|
324
|
+
const postIdOffset = profileIdChunk.offset + platformSpec.profileId.len + 1;
|
|
325
|
+
const postIdBuf = this.script.subarray(postIdOffset, postIdOffset + postIdSpec.len);
|
|
326
|
+
try {
|
|
327
|
+
switch (platform) {
|
|
328
|
+
case 'lotusia':
|
|
329
|
+
return postIdBuf.toString('hex');
|
|
330
|
+
case 'twitter':
|
|
331
|
+
return postIdBuf.readBigUInt64BE(0).toString();
|
|
332
|
+
default:
|
|
333
|
+
return undefined;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
catch (e) {
|
|
337
|
+
return undefined;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
processComment(scripts) {
|
|
341
|
+
let commentBuf = Buffer.alloc(0);
|
|
342
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
343
|
+
const script = scripts[i];
|
|
344
|
+
if (script.readUInt8(1) !== OpCode.OP_PUSHDATA1) {
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
const dataSize = script.readUInt8(2);
|
|
348
|
+
if (isNaN(dataSize) || dataSize > MAX_OP_RETURN_DATA) {
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
commentBuf = Buffer.concat([commentBuf, script.subarray(3, 3 + dataSize)]);
|
|
352
|
+
}
|
|
353
|
+
if (!commentBuf) {
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
return new Uint8Array(commentBuf);
|
|
357
|
+
}
|
|
358
|
+
processScriptRANK() {
|
|
359
|
+
const sentiment = this.processSentiment();
|
|
360
|
+
if (!sentiment) {
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
const platform = this.processPlatform();
|
|
364
|
+
if (!platform) {
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
const profileId = this.processProfileId(platform);
|
|
368
|
+
if (!profileId) {
|
|
369
|
+
return null;
|
|
370
|
+
}
|
|
371
|
+
const output = {
|
|
372
|
+
sentiment,
|
|
373
|
+
platform,
|
|
374
|
+
profileId,
|
|
375
|
+
};
|
|
376
|
+
const postId = this.processPostId(platform);
|
|
377
|
+
if (postId) {
|
|
378
|
+
output.postId = postId;
|
|
379
|
+
}
|
|
380
|
+
return output;
|
|
381
|
+
}
|
|
382
|
+
processScriptRNKC(burnedSats, options) {
|
|
383
|
+
if (typeof burnedSats === 'bigint') {
|
|
384
|
+
burnedSats = Number(burnedSats);
|
|
385
|
+
}
|
|
386
|
+
if (this.supplementalScripts.length === 0 ||
|
|
387
|
+
this.supplementalScripts.length > 2) {
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
const inReplyToPlatform = this.processPlatform();
|
|
391
|
+
if (!inReplyToPlatform) {
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
const data = this.processComment(this.supplementalScripts);
|
|
395
|
+
if (!data) {
|
|
396
|
+
return null;
|
|
397
|
+
}
|
|
398
|
+
if (data.length < (options?.minDataLength ?? RNKC_MIN_DATA_LENGTH)) {
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
if (burnedSats < (options?.minFeeRate ?? RNKC_MIN_FEE_RATE) * data.length) {
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
const output = {
|
|
405
|
+
data,
|
|
406
|
+
feeRate: Math.floor(burnedSats / data.length),
|
|
407
|
+
inReplyToPlatform,
|
|
408
|
+
inReplyToProfileId: undefined,
|
|
409
|
+
inReplyToPostId: undefined,
|
|
410
|
+
};
|
|
411
|
+
const profileId = this.processProfileId(inReplyToPlatform);
|
|
412
|
+
if (profileId) {
|
|
413
|
+
output.inReplyToProfileId = profileId;
|
|
414
|
+
const postId = this.processPostId(inReplyToPlatform);
|
|
415
|
+
if (postId) {
|
|
416
|
+
output.inReplyToPostId = postId;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return output;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare enum OpCode {
|
|
2
|
+
OP_RETURN = 106,
|
|
3
|
+
OP_PUSHDATA1 = 76,
|
|
4
|
+
OP_0 = 0,
|
|
5
|
+
OP_1 = 81,
|
|
6
|
+
OP_2 = 82,
|
|
7
|
+
OP_3 = 83,
|
|
8
|
+
OP_4 = 84,
|
|
9
|
+
OP_5 = 85,
|
|
10
|
+
OP_6 = 86,
|
|
11
|
+
OP_7 = 87,
|
|
12
|
+
OP_8 = 88,
|
|
13
|
+
OP_9 = 89,
|
|
14
|
+
OP_10 = 90,
|
|
15
|
+
OP_11 = 91,
|
|
16
|
+
OP_12 = 92,
|
|
17
|
+
OP_13 = 93,
|
|
18
|
+
OP_14 = 94,
|
|
19
|
+
OP_15 = 95,
|
|
20
|
+
OP_16 = 96
|
|
21
|
+
}
|
|
22
|
+
export default OpCode;
|
|
23
|
+
//# sourceMappingURL=opcode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opcode.d.ts","sourceRoot":"","sources":["../../../lib/rank/opcode.ts"],"names":[],"mappings":"AAIA,aAAK,MAAM;IACT,SAAS,MAAO;IAChB,YAAY,KAAO;IAEnB,IAAI,IAAO;IACX,IAAI,KAAO;IACX,IAAI,KAAO;IACX,IAAI,KAAO;IACX,IAAI,KAAO;IACX,IAAI,KAAO;IACX,IAAI,KAAO;IACX,IAAI,KAAO;IACX,IAAI,KAAO;IACX,IAAI,KAAO;IACX,KAAK,KAAO;IACZ,KAAK,KAAO;IACZ,KAAK,KAAO;IACZ,KAAK,KAAO;IACZ,KAAK,KAAO;IACZ,KAAK,KAAO;IACZ,KAAK,KAAO;CACb;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var OpCode;
|
|
2
|
+
(function (OpCode) {
|
|
3
|
+
OpCode[OpCode["OP_RETURN"] = 106] = "OP_RETURN";
|
|
4
|
+
OpCode[OpCode["OP_PUSHDATA1"] = 76] = "OP_PUSHDATA1";
|
|
5
|
+
OpCode[OpCode["OP_0"] = 0] = "OP_0";
|
|
6
|
+
OpCode[OpCode["OP_1"] = 81] = "OP_1";
|
|
7
|
+
OpCode[OpCode["OP_2"] = 82] = "OP_2";
|
|
8
|
+
OpCode[OpCode["OP_3"] = 83] = "OP_3";
|
|
9
|
+
OpCode[OpCode["OP_4"] = 84] = "OP_4";
|
|
10
|
+
OpCode[OpCode["OP_5"] = 85] = "OP_5";
|
|
11
|
+
OpCode[OpCode["OP_6"] = 86] = "OP_6";
|
|
12
|
+
OpCode[OpCode["OP_7"] = 87] = "OP_7";
|
|
13
|
+
OpCode[OpCode["OP_8"] = 88] = "OP_8";
|
|
14
|
+
OpCode[OpCode["OP_9"] = 89] = "OP_9";
|
|
15
|
+
OpCode[OpCode["OP_10"] = 90] = "OP_10";
|
|
16
|
+
OpCode[OpCode["OP_11"] = 91] = "OP_11";
|
|
17
|
+
OpCode[OpCode["OP_12"] = 92] = "OP_12";
|
|
18
|
+
OpCode[OpCode["OP_13"] = 93] = "OP_13";
|
|
19
|
+
OpCode[OpCode["OP_14"] = 94] = "OP_14";
|
|
20
|
+
OpCode[OpCode["OP_15"] = 95] = "OP_15";
|
|
21
|
+
OpCode[OpCode["OP_16"] = 96] = "OP_16";
|
|
22
|
+
})(OpCode || (OpCode = {}));
|
|
23
|
+
export default OpCode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script.d.ts","sourceRoot":"","sources":["../../../lib/rank/script.ts"],"names":[],"mappings":"AAaA,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAK3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../../lib/rank/transaction.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAG7D,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,WAAW,GAAG,MAAM,GAAG,MAAM,QAUnE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Transaction } from '../bitcore/transaction/index.js';
|
|
2
|
+
export function processTransaction(tx) {
|
|
3
|
+
if (typeof tx === 'string') {
|
|
4
|
+
if (!/^[a-fA-F0-9]+$/.test(tx)) {
|
|
5
|
+
throw new Error('Invalid transaction string format');
|
|
6
|
+
}
|
|
7
|
+
tx = Transaction.fromString(tx);
|
|
8
|
+
}
|
|
9
|
+
else if (tx instanceof Buffer) {
|
|
10
|
+
tx = Transaction.fromBuffer(tx);
|
|
11
|
+
}
|
|
12
|
+
}
|