nara-sdk 1.0.87 → 1.0.88

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/index.ts CHANGED
@@ -134,6 +134,12 @@ export {
134
134
  makeLogActivityIx,
135
135
  makeLogActivityWithReferralIx,
136
136
  setReferral,
137
+ // Agent index
138
+ getAgentIndex,
139
+ registerAgentIndex,
140
+ unregisterAgentIndex,
141
+ makeRegisterAgentIndexIx,
142
+ makeUnregisterAgentIndexIx,
137
143
  // Twitter verification
138
144
  getAgentTwitter,
139
145
  getTweetVerify,
@@ -163,6 +169,7 @@ export {
163
169
  withdrawTwitterVerifyFees,
164
170
  type AgentRecord,
165
171
  type AgentInfo,
172
+ type AgentIndexInfo,
166
173
  type AgentTwitterInfo,
167
174
  type TweetVerifyInfo,
168
175
  type TweetRecordInfo,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nara-sdk",
3
- "version": "1.0.87",
3
+ "version": "1.0.88",
4
4
  "description": "SDK for the Nara chain (Solana-compatible)",
5
5
  "module": "index.ts",
6
6
  "main": "index.ts",
@@ -56,6 +56,14 @@ export interface AgentInfo {
56
56
  metadata: string | null;
57
57
  }
58
58
 
59
+ export interface AgentIndexInfo {
60
+ /** Agent PDA that owns this index entry */
61
+ agent: PublicKey;
62
+ /** agent_id of the owning agent */
63
+ agentId: string;
64
+ createdAt: number;
65
+ }
66
+
59
67
  export interface AgentTwitterInfo {
60
68
  agentId: string;
61
69
  status: number;
@@ -181,6 +189,14 @@ function getTreasuryPda(programId: PublicKey): PublicKey {
181
189
  return pda;
182
190
  }
183
191
 
192
+ function getAgentIndexPda(programId: PublicKey, indexStr: string): PublicKey {
193
+ const [pda] = PublicKey.findProgramAddressSync(
194
+ [Buffer.from("agent_index"), Buffer.from(indexStr)],
195
+ programId
196
+ );
197
+ return pda;
198
+ }
199
+
184
200
  function getTwitterPda(programId: PublicKey, agentPda: PublicKey): PublicKey {
185
201
  const [pda] = PublicKey.findProgramAddressSync(
186
202
  [Buffer.from("twitter"), agentPda.toBuffer()],
@@ -1087,6 +1103,133 @@ export async function setReferral(
1087
1103
  return sendTx(connection, wallet, [ix]);
1088
1104
  }
1089
1105
 
1106
+ // ─── Agent Index ────────────────────────────────────────────────
1107
+
1108
+ /**
1109
+ * Parse AgentIndex account data (bytemuck zero-copy layout).
1110
+ * Layout (after 8-byte discriminator):
1111
+ * 32 agent | 8 created_at | 4 agent_id_len | 4 _padding |
1112
+ * 32 agent_id | 32 _reserved
1113
+ */
1114
+ function parseAgentIndexData(data: Buffer | Uint8Array): AgentIndexInfo {
1115
+ const buf = Buffer.from(data);
1116
+ let offset = 8;
1117
+ const agent = new PublicKey(buf.subarray(offset, offset + 32)); offset += 32;
1118
+ const createdAt = Number(buf.readBigInt64LE(offset)); offset += 8;
1119
+ const agentIdLen = buf.readUInt32LE(offset); offset += 4;
1120
+ offset += 4; // _padding
1121
+ const agentId = buf.subarray(offset, offset + agentIdLen).toString("utf-8");
1122
+ return { agent, agentId, createdAt };
1123
+ }
1124
+
1125
+ /**
1126
+ * Look up an agent_index entry by index string.
1127
+ * Returns null if no agent has claimed this index.
1128
+ */
1129
+ export async function getAgentIndex(
1130
+ connection: Connection,
1131
+ indexStr: string,
1132
+ options?: AgentRegistryOptions
1133
+ ): Promise<AgentIndexInfo | null> {
1134
+ const pid = new PublicKey(options?.programId ?? DEFAULT_AGENT_REGISTRY_PROGRAM_ID);
1135
+ const pda = getAgentIndexPda(pid, indexStr);
1136
+ const accountInfo = await connection.getAccountInfo(pda);
1137
+ if (!accountInfo) return null;
1138
+ return parseAgentIndexData(accountInfo.data);
1139
+ }
1140
+
1141
+ /**
1142
+ * Build a registerAgentIndex instruction without sending it.
1143
+ */
1144
+ export async function makeRegisterAgentIndexIx(
1145
+ connection: Connection,
1146
+ payer: PublicKey,
1147
+ authority: PublicKey,
1148
+ agentId: string,
1149
+ indexStr: string,
1150
+ options?: AgentRegistryOptions
1151
+ ): Promise<TransactionInstruction> {
1152
+ const program = createProgram(connection, Keypair.generate(), options?.programId);
1153
+ const agent = getAgentPda(program.programId, agentId);
1154
+ return program.methods
1155
+ .registerAgentIndex(indexStr)
1156
+ .accounts({ payer, authority, agent } as any)
1157
+ .instruction();
1158
+ }
1159
+
1160
+ /**
1161
+ * Register a custom index string that points to the given agent.
1162
+ * The (index_str → agent_id) mapping can be looked up via getAgentIndex.
1163
+ */
1164
+ export async function registerAgentIndex(
1165
+ connection: Connection,
1166
+ wallet: Keypair,
1167
+ agentId: string,
1168
+ indexStr: string,
1169
+ options?: AgentRegistryOptions,
1170
+ payer?: Keypair
1171
+ ): Promise<{ signature: string; agentIndexPda: PublicKey }> {
1172
+ const payerKp = payer ?? wallet;
1173
+ const program = createProgram(connection, payerKp, options?.programId);
1174
+ const agent = getAgentPda(program.programId, agentId);
1175
+ const ix = await program.methods
1176
+ .registerAgentIndex(indexStr)
1177
+ .accounts({
1178
+ payer: payerKp.publicKey,
1179
+ authority: wallet.publicKey,
1180
+ agent,
1181
+ } as any)
1182
+ .instruction();
1183
+ const signers = payer && !payer.publicKey.equals(wallet.publicKey) ? [wallet] : [];
1184
+ const signature = await sendTx(connection, payerKp, [ix], signers);
1185
+ return { signature, agentIndexPda: getAgentIndexPda(program.programId, indexStr) };
1186
+ }
1187
+
1188
+ /**
1189
+ * Build an unregisterAgentIndex instruction without sending it.
1190
+ */
1191
+ export async function makeUnregisterAgentIndexIx(
1192
+ connection: Connection,
1193
+ rentDestination: PublicKey,
1194
+ authority: PublicKey,
1195
+ agentId: string,
1196
+ indexStr: string,
1197
+ options?: AgentRegistryOptions
1198
+ ): Promise<TransactionInstruction> {
1199
+ const program = createProgram(connection, Keypair.generate(), options?.programId);
1200
+ const agent = getAgentPda(program.programId, agentId);
1201
+ return program.methods
1202
+ .unregisterAgentIndex(indexStr)
1203
+ .accounts({ rentDestination, authority, agent } as any)
1204
+ .instruction();
1205
+ }
1206
+
1207
+ /**
1208
+ * Unregister a custom index string and reclaim rent.
1209
+ * The signing wallet must be the agent's authority.
1210
+ * @param rentDestination - Account to receive reclaimed rent (defaults to wallet pubkey).
1211
+ */
1212
+ export async function unregisterAgentIndex(
1213
+ connection: Connection,
1214
+ wallet: Keypair,
1215
+ agentId: string,
1216
+ indexStr: string,
1217
+ options?: AgentRegistryOptions,
1218
+ rentDestination?: PublicKey
1219
+ ): Promise<string> {
1220
+ const program = createProgram(connection, wallet, options?.programId);
1221
+ const agent = getAgentPda(program.programId, agentId);
1222
+ const ix = await program.methods
1223
+ .unregisterAgentIndex(indexStr)
1224
+ .accounts({
1225
+ rentDestination: rentDestination ?? wallet.publicKey,
1226
+ authority: wallet.publicKey,
1227
+ agent,
1228
+ } as any)
1229
+ .instruction();
1230
+ return sendTx(connection, wallet, [ix]);
1231
+ }
1232
+
1090
1233
  // ─── Admin functions ────────────────────────────────────────────
1091
1234
 
1092
1235
  /**
@@ -1959,6 +1959,74 @@
1959
1959
  }
1960
1960
  ]
1961
1961
  },
1962
+ {
1963
+ "name": "register_agent_index",
1964
+ "discriminator": [
1965
+ 193,
1966
+ 207,
1967
+ 223,
1968
+ 226,
1969
+ 130,
1970
+ 228,
1971
+ 161,
1972
+ 207
1973
+ ],
1974
+ "accounts": [
1975
+ {
1976
+ "name": "payer",
1977
+ "writable": true,
1978
+ "signer": true
1979
+ },
1980
+ {
1981
+ "name": "authority",
1982
+ "signer": true,
1983
+ "relations": [
1984
+ "agent"
1985
+ ]
1986
+ },
1987
+ {
1988
+ "name": "agent"
1989
+ },
1990
+ {
1991
+ "name": "agent_index",
1992
+ "writable": true,
1993
+ "pda": {
1994
+ "seeds": [
1995
+ {
1996
+ "kind": "const",
1997
+ "value": [
1998
+ 97,
1999
+ 103,
2000
+ 101,
2001
+ 110,
2002
+ 116,
2003
+ 95,
2004
+ 105,
2005
+ 110,
2006
+ 100,
2007
+ 101,
2008
+ 120
2009
+ ]
2010
+ },
2011
+ {
2012
+ "kind": "arg",
2013
+ "path": "index_str"
2014
+ }
2015
+ ]
2016
+ }
2017
+ },
2018
+ {
2019
+ "name": "system_program",
2020
+ "address": "11111111111111111111111111111111"
2021
+ }
2022
+ ],
2023
+ "args": [
2024
+ {
2025
+ "name": "index_str",
2026
+ "type": "string"
2027
+ }
2028
+ ]
2029
+ },
1962
2030
  {
1963
2031
  "name": "register_agent_with_referral",
1964
2032
  "discriminator": [
@@ -3540,6 +3608,73 @@
3540
3608
  }
3541
3609
  ]
3542
3610
  },
3611
+ {
3612
+ "name": "unregister_agent_index",
3613
+ "discriminator": [
3614
+ 245,
3615
+ 18,
3616
+ 46,
3617
+ 12,
3618
+ 147,
3619
+ 155,
3620
+ 203,
3621
+ 169
3622
+ ],
3623
+ "accounts": [
3624
+ {
3625
+ "name": "rent_destination",
3626
+ "writable": true
3627
+ },
3628
+ {
3629
+ "name": "authority",
3630
+ "signer": true,
3631
+ "relations": [
3632
+ "agent"
3633
+ ]
3634
+ },
3635
+ {
3636
+ "name": "agent"
3637
+ },
3638
+ {
3639
+ "name": "agent_index",
3640
+ "writable": true,
3641
+ "pda": {
3642
+ "seeds": [
3643
+ {
3644
+ "kind": "const",
3645
+ "value": [
3646
+ 97,
3647
+ 103,
3648
+ 101,
3649
+ 110,
3650
+ 116,
3651
+ 95,
3652
+ 105,
3653
+ 110,
3654
+ 100,
3655
+ 101,
3656
+ 120
3657
+ ]
3658
+ },
3659
+ {
3660
+ "kind": "arg",
3661
+ "path": "index_str"
3662
+ }
3663
+ ]
3664
+ }
3665
+ },
3666
+ {
3667
+ "name": "system_program",
3668
+ "address": "11111111111111111111111111111111"
3669
+ }
3670
+ ],
3671
+ "args": [
3672
+ {
3673
+ "name": "index_str",
3674
+ "type": "string"
3675
+ }
3676
+ ]
3677
+ },
3543
3678
  {
3544
3679
  "name": "update_activity_config",
3545
3680
  "discriminator": [
@@ -4502,6 +4637,19 @@
4502
4637
  }
4503
4638
  ],
4504
4639
  "accounts": [
4640
+ {
4641
+ "name": "AgentIndex",
4642
+ "discriminator": [
4643
+ 241,
4644
+ 154,
4645
+ 35,
4646
+ 103,
4647
+ 180,
4648
+ 141,
4649
+ 49,
4650
+ 179
4651
+ ]
4652
+ },
4505
4653
  {
4506
4654
  "name": "AgentState",
4507
4655
  "discriminator": [
@@ -4875,6 +5023,21 @@
4875
5023
  "code": 6047,
4876
5024
  "name": "TwitterNotRejected",
4877
5025
  "msg": "Twitter binding is not in rejected status"
5026
+ },
5027
+ {
5028
+ "code": 6048,
5029
+ "name": "AgentIndexEmpty",
5030
+ "msg": "Agent index string is empty"
5031
+ },
5032
+ {
5033
+ "code": 6049,
5034
+ "name": "AgentIndexTooLong",
5035
+ "msg": "Agent index string too long"
5036
+ },
5037
+ {
5038
+ "code": 6050,
5039
+ "name": "AgentIndexMismatch",
5040
+ "msg": "Agent index does not belong to the given agent"
4878
5041
  }
4879
5042
  ],
4880
5043
  "types": [
@@ -4922,6 +5085,69 @@
4922
5085
  ]
4923
5086
  }
4924
5087
  },
5088
+ {
5089
+ "name": "AgentIndex",
5090
+ "docs": [
5091
+ "Per-agent custom index entry. Lets an agent claim arbitrary index strings",
5092
+ "that point back to its agent_id.",
5093
+ "Seeds: [SEED_AGENT_INDEX, index_str.as_bytes()]"
5094
+ ],
5095
+ "serialization": "bytemuck",
5096
+ "repr": {
5097
+ "kind": "c"
5098
+ },
5099
+ "type": {
5100
+ "kind": "struct",
5101
+ "fields": [
5102
+ {
5103
+ "name": "agent",
5104
+ "docs": [
5105
+ "The AgentState PDA that owns this index entry"
5106
+ ],
5107
+ "type": "pubkey"
5108
+ },
5109
+ {
5110
+ "name": "created_at",
5111
+ "docs": [
5112
+ "Unix timestamp when this index was registered"
5113
+ ],
5114
+ "type": "i64"
5115
+ },
5116
+ {
5117
+ "name": "agent_id_len",
5118
+ "docs": [
5119
+ "Length of the agent_id stored below"
5120
+ ],
5121
+ "type": "u32"
5122
+ },
5123
+ {
5124
+ "name": "_padding",
5125
+ "type": "u32"
5126
+ },
5127
+ {
5128
+ "name": "agent_id",
5129
+ "docs": [
5130
+ "agent_id of the owning agent (zero-padded)"
5131
+ ],
5132
+ "type": {
5133
+ "array": [
5134
+ "u8",
5135
+ 32
5136
+ ]
5137
+ }
5138
+ },
5139
+ {
5140
+ "name": "_reserved",
5141
+ "type": {
5142
+ "array": [
5143
+ "u8",
5144
+ 32
5145
+ ]
5146
+ }
5147
+ }
5148
+ ]
5149
+ }
5150
+ },
4925
5151
  {
4926
5152
  "name": "AgentState",
4927
5153
  "docs": [
@@ -1965,6 +1965,74 @@ export type NaraAgentRegistry = {
1965
1965
  }
1966
1966
  ]
1967
1967
  },
1968
+ {
1969
+ "name": "registerAgentIndex",
1970
+ "discriminator": [
1971
+ 193,
1972
+ 207,
1973
+ 223,
1974
+ 226,
1975
+ 130,
1976
+ 228,
1977
+ 161,
1978
+ 207
1979
+ ],
1980
+ "accounts": [
1981
+ {
1982
+ "name": "payer",
1983
+ "writable": true,
1984
+ "signer": true
1985
+ },
1986
+ {
1987
+ "name": "authority",
1988
+ "signer": true,
1989
+ "relations": [
1990
+ "agent"
1991
+ ]
1992
+ },
1993
+ {
1994
+ "name": "agent"
1995
+ },
1996
+ {
1997
+ "name": "agentIndex",
1998
+ "writable": true,
1999
+ "pda": {
2000
+ "seeds": [
2001
+ {
2002
+ "kind": "const",
2003
+ "value": [
2004
+ 97,
2005
+ 103,
2006
+ 101,
2007
+ 110,
2008
+ 116,
2009
+ 95,
2010
+ 105,
2011
+ 110,
2012
+ 100,
2013
+ 101,
2014
+ 120
2015
+ ]
2016
+ },
2017
+ {
2018
+ "kind": "arg",
2019
+ "path": "indexStr"
2020
+ }
2021
+ ]
2022
+ }
2023
+ },
2024
+ {
2025
+ "name": "systemProgram",
2026
+ "address": "11111111111111111111111111111111"
2027
+ }
2028
+ ],
2029
+ "args": [
2030
+ {
2031
+ "name": "indexStr",
2032
+ "type": "string"
2033
+ }
2034
+ ]
2035
+ },
1968
2036
  {
1969
2037
  "name": "registerAgentWithReferral",
1970
2038
  "discriminator": [
@@ -3546,6 +3614,73 @@ export type NaraAgentRegistry = {
3546
3614
  }
3547
3615
  ]
3548
3616
  },
3617
+ {
3618
+ "name": "unregisterAgentIndex",
3619
+ "discriminator": [
3620
+ 245,
3621
+ 18,
3622
+ 46,
3623
+ 12,
3624
+ 147,
3625
+ 155,
3626
+ 203,
3627
+ 169
3628
+ ],
3629
+ "accounts": [
3630
+ {
3631
+ "name": "rentDestination",
3632
+ "writable": true
3633
+ },
3634
+ {
3635
+ "name": "authority",
3636
+ "signer": true,
3637
+ "relations": [
3638
+ "agent"
3639
+ ]
3640
+ },
3641
+ {
3642
+ "name": "agent"
3643
+ },
3644
+ {
3645
+ "name": "agentIndex",
3646
+ "writable": true,
3647
+ "pda": {
3648
+ "seeds": [
3649
+ {
3650
+ "kind": "const",
3651
+ "value": [
3652
+ 97,
3653
+ 103,
3654
+ 101,
3655
+ 110,
3656
+ 116,
3657
+ 95,
3658
+ 105,
3659
+ 110,
3660
+ 100,
3661
+ 101,
3662
+ 120
3663
+ ]
3664
+ },
3665
+ {
3666
+ "kind": "arg",
3667
+ "path": "indexStr"
3668
+ }
3669
+ ]
3670
+ }
3671
+ },
3672
+ {
3673
+ "name": "systemProgram",
3674
+ "address": "11111111111111111111111111111111"
3675
+ }
3676
+ ],
3677
+ "args": [
3678
+ {
3679
+ "name": "indexStr",
3680
+ "type": "string"
3681
+ }
3682
+ ]
3683
+ },
3549
3684
  {
3550
3685
  "name": "updateActivityConfig",
3551
3686
  "discriminator": [
@@ -4508,6 +4643,19 @@ export type NaraAgentRegistry = {
4508
4643
  }
4509
4644
  ],
4510
4645
  "accounts": [
4646
+ {
4647
+ "name": "agentIndex",
4648
+ "discriminator": [
4649
+ 241,
4650
+ 154,
4651
+ 35,
4652
+ 103,
4653
+ 180,
4654
+ 141,
4655
+ 49,
4656
+ 179
4657
+ ]
4658
+ },
4511
4659
  {
4512
4660
  "name": "agentState",
4513
4661
  "discriminator": [
@@ -4881,6 +5029,21 @@ export type NaraAgentRegistry = {
4881
5029
  "code": 6047,
4882
5030
  "name": "twitterNotRejected",
4883
5031
  "msg": "Twitter binding is not in rejected status"
5032
+ },
5033
+ {
5034
+ "code": 6048,
5035
+ "name": "agentIndexEmpty",
5036
+ "msg": "Agent index string is empty"
5037
+ },
5038
+ {
5039
+ "code": 6049,
5040
+ "name": "agentIndexTooLong",
5041
+ "msg": "Agent index string too long"
5042
+ },
5043
+ {
5044
+ "code": 6050,
5045
+ "name": "agentIndexMismatch",
5046
+ "msg": "Agent index does not belong to the given agent"
4884
5047
  }
4885
5048
  ],
4886
5049
  "types": [
@@ -4928,6 +5091,69 @@ export type NaraAgentRegistry = {
4928
5091
  ]
4929
5092
  }
4930
5093
  },
5094
+ {
5095
+ "name": "agentIndex",
5096
+ "docs": [
5097
+ "Per-agent custom index entry. Lets an agent claim arbitrary index strings",
5098
+ "that point back to its agent_id.",
5099
+ "Seeds: [SEED_AGENT_INDEX, index_str.as_bytes()]"
5100
+ ],
5101
+ "serialization": "bytemuck",
5102
+ "repr": {
5103
+ "kind": "c"
5104
+ },
5105
+ "type": {
5106
+ "kind": "struct",
5107
+ "fields": [
5108
+ {
5109
+ "name": "agent",
5110
+ "docs": [
5111
+ "The AgentState PDA that owns this index entry"
5112
+ ],
5113
+ "type": "pubkey"
5114
+ },
5115
+ {
5116
+ "name": "createdAt",
5117
+ "docs": [
5118
+ "Unix timestamp when this index was registered"
5119
+ ],
5120
+ "type": "i64"
5121
+ },
5122
+ {
5123
+ "name": "agentIdLen",
5124
+ "docs": [
5125
+ "Length of the agent_id stored below"
5126
+ ],
5127
+ "type": "u32"
5128
+ },
5129
+ {
5130
+ "name": "padding",
5131
+ "type": "u32"
5132
+ },
5133
+ {
5134
+ "name": "agentId",
5135
+ "docs": [
5136
+ "agent_id of the owning agent (zero-padded)"
5137
+ ],
5138
+ "type": {
5139
+ "array": [
5140
+ "u8",
5141
+ 32
5142
+ ]
5143
+ }
5144
+ },
5145
+ {
5146
+ "name": "reserved",
5147
+ "type": {
5148
+ "array": [
5149
+ "u8",
5150
+ 32
5151
+ ]
5152
+ }
5153
+ }
5154
+ ]
5155
+ }
5156
+ },
4931
5157
  {
4932
5158
  "name": "agentState",
4933
5159
  "docs": [