@unicitylabs/nostr-js-sdk 0.2.0 → 0.2.1
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 +29 -7
- package/dist/browser/index.js +35 -5
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.min.js +1 -1
- package/dist/browser/index.min.js.map +1 -1
- package/dist/browser/index.umd.js +35 -5
- package/dist/browser/index.umd.js.map +1 -1
- package/dist/browser/index.umd.min.js +5 -5
- package/dist/browser/index.umd.min.js.map +1 -1
- package/dist/cjs/token/TokenTransferProtocol.js +35 -5
- package/dist/cjs/token/TokenTransferProtocol.js.map +1 -1
- package/dist/esm/token/TokenTransferProtocol.js +34 -5
- package/dist/esm/token/TokenTransferProtocol.js.map +1 -1
- package/dist/types/token/TokenTransferProtocol.d.ts +22 -3
- package/dist/types/token/TokenTransferProtocol.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -9830,16 +9830,32 @@
|
|
|
9830
9830
|
* - ["type", "token_transfer"] - Event type
|
|
9831
9831
|
* - ["amount", "<amount>"] - Optional amount
|
|
9832
9832
|
* - ["symbol", "<symbol>"] - Optional token symbol
|
|
9833
|
+
* - ["e", "<event_id>", "", "reply"] - Optional reply-to event (for payment request correlation)
|
|
9833
9834
|
* - Content: NIP-04 encrypted "token_transfer:{tokenJson}"
|
|
9834
9835
|
*
|
|
9835
9836
|
* @param keyManager Key manager with signing keys
|
|
9836
9837
|
* @param recipientPubkeyHex Recipient's public key (hex)
|
|
9837
9838
|
* @param tokenJson Token JSON string
|
|
9838
|
-
* @param
|
|
9839
|
-
* @param symbol Optional token symbol for metadata
|
|
9839
|
+
* @param amountOrOptions Optional amount for metadata, or options object
|
|
9840
|
+
* @param symbol Optional token symbol for metadata (ignored if options object used)
|
|
9840
9841
|
* @returns Signed event
|
|
9841
9842
|
*/
|
|
9842
|
-
async function createTokenTransferEvent(keyManager, recipientPubkeyHex, tokenJson,
|
|
9843
|
+
async function createTokenTransferEvent(keyManager, recipientPubkeyHex, tokenJson, amountOrOptions, symbol) {
|
|
9844
|
+
// Parse options (support both old and new signatures)
|
|
9845
|
+
let amount;
|
|
9846
|
+
let tokenSymbol;
|
|
9847
|
+
let replyToEventId;
|
|
9848
|
+
if (amountOrOptions !== undefined && typeof amountOrOptions === 'object') {
|
|
9849
|
+
// New options object signature
|
|
9850
|
+
amount = amountOrOptions.amount;
|
|
9851
|
+
tokenSymbol = amountOrOptions.symbol;
|
|
9852
|
+
replyToEventId = amountOrOptions.replyToEventId;
|
|
9853
|
+
}
|
|
9854
|
+
else {
|
|
9855
|
+
// Old positional arguments signature
|
|
9856
|
+
amount = amountOrOptions;
|
|
9857
|
+
tokenSymbol = symbol;
|
|
9858
|
+
}
|
|
9843
9859
|
// Encrypt the token data
|
|
9844
9860
|
const message = MESSAGE_PREFIX$1 + tokenJson;
|
|
9845
9861
|
const encryptedContent = await keyManager.encryptHex(message, recipientPubkeyHex);
|
|
@@ -9851,8 +9867,12 @@
|
|
|
9851
9867
|
if (amount !== undefined) {
|
|
9852
9868
|
tags.push(['amount', String(amount)]);
|
|
9853
9869
|
}
|
|
9854
|
-
if (
|
|
9855
|
-
tags.push(['symbol',
|
|
9870
|
+
if (tokenSymbol !== undefined) {
|
|
9871
|
+
tags.push(['symbol', tokenSymbol]);
|
|
9872
|
+
}
|
|
9873
|
+
// Add optional reply-to event reference (for payment request correlation)
|
|
9874
|
+
if (replyToEventId !== undefined && replyToEventId.length > 0) {
|
|
9875
|
+
tags.push(['e', replyToEventId, '', 'reply']);
|
|
9856
9876
|
}
|
|
9857
9877
|
const event = Event.create(keyManager, {
|
|
9858
9878
|
kind: TOKEN_TRANSFER,
|
|
@@ -9940,6 +9960,15 @@
|
|
|
9940
9960
|
function getSymbol(event) {
|
|
9941
9961
|
return event.getTagValue('symbol');
|
|
9942
9962
|
}
|
|
9963
|
+
/**
|
|
9964
|
+
* Get the reply-to event ID from a token transfer event.
|
|
9965
|
+
* Used to correlate token transfers with payment requests.
|
|
9966
|
+
* @param event Token transfer event
|
|
9967
|
+
* @returns Referenced event ID, or undefined if not present
|
|
9968
|
+
*/
|
|
9969
|
+
function getReplyToEventId(event) {
|
|
9970
|
+
return event.getTagValue('e');
|
|
9971
|
+
}
|
|
9943
9972
|
/**
|
|
9944
9973
|
* Check if an event is a token transfer.
|
|
9945
9974
|
* @param event Event to check
|
|
@@ -9971,6 +10000,7 @@
|
|
|
9971
10000
|
createTokenTransferEvent: createTokenTransferEvent,
|
|
9972
10001
|
getAmount: getAmount$1,
|
|
9973
10002
|
getRecipient: getRecipient,
|
|
10003
|
+
getReplyToEventId: getReplyToEventId,
|
|
9974
10004
|
getSender: getSender$1,
|
|
9975
10005
|
getSymbol: getSymbol,
|
|
9976
10006
|
isTokenTransfer: isTokenTransfer,
|