@thru/passkey-manager 0.2.1 → 0.2.3
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/dist/index.cjs +499 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -2
- package/dist/index.d.ts +24 -2
- package/dist/index.js +495 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/abi/thru/program/passkey_manager/types.ts +586 -1
- package/src/constants.ts +2 -1
- package/src/index.ts +4 -1
- package/src/instructions/register-credential.ts +33 -0
- package/src/seeds.ts +33 -0
- package/src/types.ts +7 -0
package/dist/index.cjs
CHANGED
|
@@ -26,6 +26,7 @@ __export(src_exports, {
|
|
|
26
26
|
INSTRUCTION_ADD_AUTHORITY: () => INSTRUCTION_ADD_AUTHORITY,
|
|
27
27
|
INSTRUCTION_CREATE: () => INSTRUCTION_CREATE,
|
|
28
28
|
INSTRUCTION_INVOKE: () => INSTRUCTION_INVOKE,
|
|
29
|
+
INSTRUCTION_REGISTER_CREDENTIAL: () => INSTRUCTION_REGISTER_CREDENTIAL,
|
|
29
30
|
INSTRUCTION_REMOVE_AUTHORITY: () => INSTRUCTION_REMOVE_AUTHORITY,
|
|
30
31
|
INSTRUCTION_TRANSFER: () => INSTRUCTION_TRANSFER,
|
|
31
32
|
INSTRUCTION_VALIDATE: () => INSTRUCTION_VALIDATE,
|
|
@@ -44,12 +45,15 @@ __export(src_exports, {
|
|
|
44
45
|
bytesToHex: () => bytesToHex,
|
|
45
46
|
compareBytes: () => compareBytes,
|
|
46
47
|
concatenateInstructions: () => concatenateInstructions,
|
|
48
|
+
createCredentialLookupSeed: () => createCredentialLookupSeed,
|
|
47
49
|
createValidateChallenge: () => createValidateChallenge,
|
|
48
50
|
createWalletSeed: () => createWalletSeed,
|
|
51
|
+
deriveCredentialLookupAddress: () => deriveCredentialLookupAddress,
|
|
49
52
|
deriveWalletAddress: () => deriveWalletAddress,
|
|
50
53
|
encodeAddAuthorityInstruction: () => encodeAddAuthorityInstruction,
|
|
51
54
|
encodeCreateInstruction: () => encodeCreateInstruction,
|
|
52
55
|
encodeInvokeInstruction: () => encodeInvokeInstruction,
|
|
56
|
+
encodeRegisterCredentialInstruction: () => encodeRegisterCredentialInstruction,
|
|
53
57
|
encodeRemoveAuthorityInstruction: () => encodeRemoveAuthorityInstruction,
|
|
54
58
|
encodeTransferInstruction: () => encodeTransferInstruction,
|
|
55
59
|
encodeValidateInstruction: () => encodeValidateInstruction,
|
|
@@ -64,13 +68,14 @@ __export(src_exports, {
|
|
|
64
68
|
module.exports = __toCommonJS(src_exports);
|
|
65
69
|
|
|
66
70
|
// src/constants.ts
|
|
67
|
-
var PASSKEY_MANAGER_PROGRAM_ADDRESS = "
|
|
71
|
+
var PASSKEY_MANAGER_PROGRAM_ADDRESS = "taUDdQyFxvM5i0HFRkEK3W45kWLyblAHSnMg4zplgUnz6Z";
|
|
68
72
|
var INSTRUCTION_CREATE = 0;
|
|
69
73
|
var INSTRUCTION_VALIDATE = 1;
|
|
70
74
|
var INSTRUCTION_TRANSFER = 2;
|
|
71
75
|
var INSTRUCTION_INVOKE = 3;
|
|
72
76
|
var INSTRUCTION_ADD_AUTHORITY = 4;
|
|
73
77
|
var INSTRUCTION_REMOVE_AUTHORITY = 5;
|
|
78
|
+
var INSTRUCTION_REGISTER_CREDENTIAL = 6;
|
|
74
79
|
var AUTHORITY_TAG_PASSKEY = 1;
|
|
75
80
|
var AUTHORITY_TAG_PUBKEY = 2;
|
|
76
81
|
|
|
@@ -5095,6 +5100,229 @@ var AddAuthorityArgsBuilder = class {
|
|
|
5095
5100
|
return view;
|
|
5096
5101
|
}
|
|
5097
5102
|
};
|
|
5103
|
+
var __tn_ir_CredentialLookup = {
|
|
5104
|
+
typeName: "CredentialLookup",
|
|
5105
|
+
root: { op: "const", value: 32n }
|
|
5106
|
+
};
|
|
5107
|
+
var CredentialLookup = class _CredentialLookup {
|
|
5108
|
+
constructor(buffer) {
|
|
5109
|
+
this.buffer = buffer;
|
|
5110
|
+
this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
5111
|
+
}
|
|
5112
|
+
static __tnCreateView(buffer, opts) {
|
|
5113
|
+
if (!buffer || buffer.length === void 0) throw new Error("CredentialLookup.__tnCreateView requires a Uint8Array");
|
|
5114
|
+
return new _CredentialLookup(new Uint8Array(buffer));
|
|
5115
|
+
}
|
|
5116
|
+
static builder() {
|
|
5117
|
+
return new CredentialLookupBuilder();
|
|
5118
|
+
}
|
|
5119
|
+
static fromBuilder(builder) {
|
|
5120
|
+
const buffer = builder.build();
|
|
5121
|
+
return _CredentialLookup.from_array(buffer);
|
|
5122
|
+
}
|
|
5123
|
+
get_wallet() {
|
|
5124
|
+
const offset = 0;
|
|
5125
|
+
const slice = this.buffer.subarray(offset, offset + 32);
|
|
5126
|
+
return Pubkey.from_array(slice);
|
|
5127
|
+
}
|
|
5128
|
+
set_wallet(value) {
|
|
5129
|
+
const sourceBytes = value.buffer;
|
|
5130
|
+
const offset = 0;
|
|
5131
|
+
this.buffer.set(sourceBytes, offset);
|
|
5132
|
+
}
|
|
5133
|
+
get wallet() {
|
|
5134
|
+
return this.get_wallet();
|
|
5135
|
+
}
|
|
5136
|
+
set wallet(value) {
|
|
5137
|
+
this.set_wallet(value);
|
|
5138
|
+
}
|
|
5139
|
+
static __tnFootprintInternal(__tnParams) {
|
|
5140
|
+
return __tnEvalFootprint3(__tn_ir_CredentialLookup.root, { params: __tnParams });
|
|
5141
|
+
}
|
|
5142
|
+
static __tnValidateInternal(buffer, __tnParams) {
|
|
5143
|
+
return __tnValidateIrTree3(__tn_ir_CredentialLookup, buffer, __tnParams);
|
|
5144
|
+
}
|
|
5145
|
+
static __tnInvokeFootprint(__tnParams) {
|
|
5146
|
+
return this.__tnFootprintInternal(__tnParams);
|
|
5147
|
+
}
|
|
5148
|
+
static __tnInvokeValidate(buffer, __tnParams) {
|
|
5149
|
+
return this.__tnValidateInternal(buffer, __tnParams);
|
|
5150
|
+
}
|
|
5151
|
+
static footprintIr() {
|
|
5152
|
+
return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
|
|
5153
|
+
}
|
|
5154
|
+
static footprint() {
|
|
5155
|
+
const irResult = this.footprintIr();
|
|
5156
|
+
const maxSafe = __tnToBigInt3(Number.MAX_SAFE_INTEGER);
|
|
5157
|
+
if (__tnBigIntGreaterThan3(irResult, maxSafe)) {
|
|
5158
|
+
throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for CredentialLookup");
|
|
5159
|
+
}
|
|
5160
|
+
return __tnBigIntToNumber3(irResult, "CredentialLookup::footprint");
|
|
5161
|
+
}
|
|
5162
|
+
static validate(buffer, _opts) {
|
|
5163
|
+
if (buffer.length < 32) return { ok: false, code: "tn.buffer_too_small", consumed: 32 };
|
|
5164
|
+
return { ok: true, consumed: 32 };
|
|
5165
|
+
}
|
|
5166
|
+
static from_array(buffer) {
|
|
5167
|
+
if (!buffer || buffer.length === void 0) {
|
|
5168
|
+
return null;
|
|
5169
|
+
}
|
|
5170
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
5171
|
+
const validation = this.validate(buffer);
|
|
5172
|
+
if (!validation.ok) {
|
|
5173
|
+
return null;
|
|
5174
|
+
}
|
|
5175
|
+
return new _CredentialLookup(buffer);
|
|
5176
|
+
}
|
|
5177
|
+
};
|
|
5178
|
+
__tnRegisterFootprint3("CredentialLookup", (params) => CredentialLookup.__tnInvokeFootprint(params));
|
|
5179
|
+
__tnRegisterValidate3("CredentialLookup", (buffer, params) => CredentialLookup.__tnInvokeValidate(buffer, params));
|
|
5180
|
+
var CredentialLookupBuilder = class {
|
|
5181
|
+
constructor() {
|
|
5182
|
+
this.buffer = new Uint8Array(32);
|
|
5183
|
+
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
5184
|
+
}
|
|
5185
|
+
set_wallet(value) {
|
|
5186
|
+
if (value.length !== 32) throw new Error("wallet expects 32 bytes");
|
|
5187
|
+
this.buffer.set(value, 0);
|
|
5188
|
+
return this;
|
|
5189
|
+
}
|
|
5190
|
+
build() {
|
|
5191
|
+
return this.buffer.slice();
|
|
5192
|
+
}
|
|
5193
|
+
buildInto(target, offset = 0) {
|
|
5194
|
+
if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
|
|
5195
|
+
target.set(this.buffer, offset);
|
|
5196
|
+
return target;
|
|
5197
|
+
}
|
|
5198
|
+
finish() {
|
|
5199
|
+
const view = CredentialLookup.from_array(this.buffer.slice());
|
|
5200
|
+
if (!view) throw new Error("failed to build CredentialLookup");
|
|
5201
|
+
return view;
|
|
5202
|
+
}
|
|
5203
|
+
};
|
|
5204
|
+
var __tn_ir_CredentialRegisteredEventData = {
|
|
5205
|
+
typeName: "CredentialRegisteredEventData",
|
|
5206
|
+
root: { op: "const", value: 64n }
|
|
5207
|
+
};
|
|
5208
|
+
var CredentialRegisteredEventData = class _CredentialRegisteredEventData {
|
|
5209
|
+
constructor(buffer) {
|
|
5210
|
+
this.buffer = buffer;
|
|
5211
|
+
this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
5212
|
+
}
|
|
5213
|
+
static __tnCreateView(buffer, opts) {
|
|
5214
|
+
if (!buffer || buffer.length === void 0) throw new Error("CredentialRegisteredEventData.__tnCreateView requires a Uint8Array");
|
|
5215
|
+
return new _CredentialRegisteredEventData(new Uint8Array(buffer));
|
|
5216
|
+
}
|
|
5217
|
+
static builder() {
|
|
5218
|
+
return new CredentialRegisteredEventDataBuilder();
|
|
5219
|
+
}
|
|
5220
|
+
static fromBuilder(builder) {
|
|
5221
|
+
const buffer = builder.build();
|
|
5222
|
+
return _CredentialRegisteredEventData.from_array(buffer);
|
|
5223
|
+
}
|
|
5224
|
+
get_wallet() {
|
|
5225
|
+
const offset = 0;
|
|
5226
|
+
const slice = this.buffer.subarray(offset, offset + 32);
|
|
5227
|
+
return Pubkey.from_array(slice);
|
|
5228
|
+
}
|
|
5229
|
+
set_wallet(value) {
|
|
5230
|
+
const sourceBytes = value.buffer;
|
|
5231
|
+
const offset = 0;
|
|
5232
|
+
this.buffer.set(sourceBytes, offset);
|
|
5233
|
+
}
|
|
5234
|
+
get wallet() {
|
|
5235
|
+
return this.get_wallet();
|
|
5236
|
+
}
|
|
5237
|
+
set wallet(value) {
|
|
5238
|
+
this.set_wallet(value);
|
|
5239
|
+
}
|
|
5240
|
+
get_lookup() {
|
|
5241
|
+
const offset = 32;
|
|
5242
|
+
const slice = this.buffer.subarray(offset, offset + 32);
|
|
5243
|
+
return Pubkey.from_array(slice);
|
|
5244
|
+
}
|
|
5245
|
+
set_lookup(value) {
|
|
5246
|
+
const sourceBytes = value.buffer;
|
|
5247
|
+
const offset = 32;
|
|
5248
|
+
this.buffer.set(sourceBytes, offset);
|
|
5249
|
+
}
|
|
5250
|
+
get lookup() {
|
|
5251
|
+
return this.get_lookup();
|
|
5252
|
+
}
|
|
5253
|
+
set lookup(value) {
|
|
5254
|
+
this.set_lookup(value);
|
|
5255
|
+
}
|
|
5256
|
+
static __tnFootprintInternal(__tnParams) {
|
|
5257
|
+
return __tnEvalFootprint3(__tn_ir_CredentialRegisteredEventData.root, { params: __tnParams });
|
|
5258
|
+
}
|
|
5259
|
+
static __tnValidateInternal(buffer, __tnParams) {
|
|
5260
|
+
return __tnValidateIrTree3(__tn_ir_CredentialRegisteredEventData, buffer, __tnParams);
|
|
5261
|
+
}
|
|
5262
|
+
static __tnInvokeFootprint(__tnParams) {
|
|
5263
|
+
return this.__tnFootprintInternal(__tnParams);
|
|
5264
|
+
}
|
|
5265
|
+
static __tnInvokeValidate(buffer, __tnParams) {
|
|
5266
|
+
return this.__tnValidateInternal(buffer, __tnParams);
|
|
5267
|
+
}
|
|
5268
|
+
static footprintIr() {
|
|
5269
|
+
return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
|
|
5270
|
+
}
|
|
5271
|
+
static footprint() {
|
|
5272
|
+
const irResult = this.footprintIr();
|
|
5273
|
+
const maxSafe = __tnToBigInt3(Number.MAX_SAFE_INTEGER);
|
|
5274
|
+
if (__tnBigIntGreaterThan3(irResult, maxSafe)) {
|
|
5275
|
+
throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for CredentialRegisteredEventData");
|
|
5276
|
+
}
|
|
5277
|
+
return __tnBigIntToNumber3(irResult, "CredentialRegisteredEventData::footprint");
|
|
5278
|
+
}
|
|
5279
|
+
static validate(buffer, _opts) {
|
|
5280
|
+
if (buffer.length < 64) return { ok: false, code: "tn.buffer_too_small", consumed: 64 };
|
|
5281
|
+
return { ok: true, consumed: 64 };
|
|
5282
|
+
}
|
|
5283
|
+
static from_array(buffer) {
|
|
5284
|
+
if (!buffer || buffer.length === void 0) {
|
|
5285
|
+
return null;
|
|
5286
|
+
}
|
|
5287
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
5288
|
+
const validation = this.validate(buffer);
|
|
5289
|
+
if (!validation.ok) {
|
|
5290
|
+
return null;
|
|
5291
|
+
}
|
|
5292
|
+
return new _CredentialRegisteredEventData(buffer);
|
|
5293
|
+
}
|
|
5294
|
+
};
|
|
5295
|
+
__tnRegisterFootprint3("CredentialRegisteredEventData", (params) => CredentialRegisteredEventData.__tnInvokeFootprint(params));
|
|
5296
|
+
__tnRegisterValidate3("CredentialRegisteredEventData", (buffer, params) => CredentialRegisteredEventData.__tnInvokeValidate(buffer, params));
|
|
5297
|
+
var CredentialRegisteredEventDataBuilder = class {
|
|
5298
|
+
constructor() {
|
|
5299
|
+
this.buffer = new Uint8Array(64);
|
|
5300
|
+
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
5301
|
+
}
|
|
5302
|
+
set_wallet(value) {
|
|
5303
|
+
if (value.length !== 32) throw new Error("wallet expects 32 bytes");
|
|
5304
|
+
this.buffer.set(value, 0);
|
|
5305
|
+
return this;
|
|
5306
|
+
}
|
|
5307
|
+
set_lookup(value) {
|
|
5308
|
+
if (value.length !== 32) throw new Error("lookup expects 32 bytes");
|
|
5309
|
+
this.buffer.set(value, 32);
|
|
5310
|
+
return this;
|
|
5311
|
+
}
|
|
5312
|
+
build() {
|
|
5313
|
+
return this.buffer.slice();
|
|
5314
|
+
}
|
|
5315
|
+
buildInto(target, offset = 0) {
|
|
5316
|
+
if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
|
|
5317
|
+
target.set(this.buffer, offset);
|
|
5318
|
+
return target;
|
|
5319
|
+
}
|
|
5320
|
+
finish() {
|
|
5321
|
+
const view = CredentialRegisteredEventData.from_array(this.buffer.slice());
|
|
5322
|
+
if (!view) throw new Error("failed to build CredentialRegisteredEventData");
|
|
5323
|
+
return view;
|
|
5324
|
+
}
|
|
5325
|
+
};
|
|
5098
5326
|
var __tn_ir_InvokeArgs = {
|
|
5099
5327
|
typeName: "InvokeArgs",
|
|
5100
5328
|
root: { op: "align", alignment: 1, node: { op: "add", left: { op: "add", left: { op: "align", alignment: 1, node: { op: "const", value: 32n } }, right: { op: "align", alignment: 2, node: { op: "const", value: 2n } } }, right: { op: "align", alignment: 1, node: { op: "mul", left: { op: "field", param: "instr.instr_len" }, right: { op: "const", value: 1n } } } } }
|
|
@@ -5435,7 +5663,7 @@ var InvokeArgsBuilder = class {
|
|
|
5435
5663
|
};
|
|
5436
5664
|
var __tn_ir_PasskeyEvent = {
|
|
5437
5665
|
typeName: "PasskeyEvent",
|
|
5438
|
-
root: { op: "align", alignment: 1, node: { op: "add", left: { op: "align", alignment: 1, node: { op: "const", value: 1n } }, right: { op: "align", alignment: 1, node: { op: "switch", tag: "PasskeyEvent::payload.event_type", cases: [{ value: 0, node: { op: "align", alignment: 1, node: { op: "const", value: 97n } } }, { value: 1, node: { op: "align", alignment: 1, node: { op: "const", value: 40n } } }, { value: 2, node: { op: "align", alignment: 1, node: { op: "const", value: 72n } } }] } } } }
|
|
5666
|
+
root: { op: "align", alignment: 1, node: { op: "add", left: { op: "align", alignment: 1, node: { op: "const", value: 1n } }, right: { op: "align", alignment: 1, node: { op: "switch", tag: "PasskeyEvent::payload.event_type", cases: [{ value: 0, node: { op: "align", alignment: 1, node: { op: "const", value: 97n } } }, { value: 1, node: { op: "align", alignment: 1, node: { op: "const", value: 40n } } }, { value: 2, node: { op: "align", alignment: 1, node: { op: "const", value: 72n } } }, { value: 3, node: { op: "align", alignment: 1, node: { op: "const", value: 64n } } }] } } } }
|
|
5439
5667
|
};
|
|
5440
5668
|
var PasskeyEvent_payload_Inner = class _PasskeyEvent_payload_Inner {
|
|
5441
5669
|
constructor(buffer, descriptor, fieldContext) {
|
|
@@ -5466,6 +5694,10 @@ var PasskeyEvent_payload_Inner = class _PasskeyEvent_payload_Inner {
|
|
|
5466
5694
|
if (!this.descriptor || this.descriptor.tag !== 2) return null;
|
|
5467
5695
|
return WalletTransferEventData.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? void 0 });
|
|
5468
5696
|
}
|
|
5697
|
+
asCredentialRegistered() {
|
|
5698
|
+
if (!this.descriptor || this.descriptor.tag !== 3) return null;
|
|
5699
|
+
return CredentialRegisteredEventData.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? void 0 });
|
|
5700
|
+
}
|
|
5469
5701
|
};
|
|
5470
5702
|
var _PasskeyEvent = class _PasskeyEvent {
|
|
5471
5703
|
constructor(buffer, params) {
|
|
@@ -5644,6 +5876,13 @@ _PasskeyEvent.payloadVariantDescriptors = Object.freeze([
|
|
|
5644
5876
|
payloadSize: 72,
|
|
5645
5877
|
payloadType: "PasskeyEvent::payload::wallet_transfer",
|
|
5646
5878
|
createPayloadBuilder: () => __tnMaybeCallBuilder(WalletTransferEventData)
|
|
5879
|
+
},
|
|
5880
|
+
{
|
|
5881
|
+
name: "credential_registered",
|
|
5882
|
+
tag: 3,
|
|
5883
|
+
payloadSize: 64,
|
|
5884
|
+
payloadType: "PasskeyEvent::payload::credential_registered",
|
|
5885
|
+
createPayloadBuilder: () => __tnMaybeCallBuilder(CredentialRegisteredEventData)
|
|
5647
5886
|
}
|
|
5648
5887
|
]);
|
|
5649
5888
|
var PasskeyEvent = _PasskeyEvent;
|
|
@@ -5991,6 +6230,221 @@ var CreateArgsBuilder = class {
|
|
|
5991
6230
|
}
|
|
5992
6231
|
}
|
|
5993
6232
|
};
|
|
6233
|
+
var __tn_ir_RegisterCredentialArgs = {
|
|
6234
|
+
typeName: "RegisterCredentialArgs",
|
|
6235
|
+
root: { op: "align", alignment: 1, node: { op: "add", left: { op: "add", left: { op: "add", left: { op: "align", alignment: 2, node: { op: "const", value: 2n } }, right: { op: "align", alignment: 2, node: { op: "const", value: 2n } } }, right: { op: "align", alignment: 1, node: { op: "const", value: 32n } } }, right: { op: "align", alignment: 1, node: { op: "call", typeName: "StateProof", args: [{ name: "proof_body.hdr.type_slot", source: "proof_body.hdr.type_slot" }, { name: "proof_body.payload_size", source: "proof_body.payload_size" }] } } } }
|
|
6236
|
+
};
|
|
6237
|
+
var RegisterCredentialArgs = class _RegisterCredentialArgs {
|
|
6238
|
+
constructor(buffer) {
|
|
6239
|
+
this.buffer = buffer;
|
|
6240
|
+
this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
6241
|
+
}
|
|
6242
|
+
static __tnCreateView(buffer, opts) {
|
|
6243
|
+
if (!buffer || buffer.length === void 0) throw new Error("RegisterCredentialArgs.__tnCreateView requires a Uint8Array");
|
|
6244
|
+
return new _RegisterCredentialArgs(new Uint8Array(buffer));
|
|
6245
|
+
}
|
|
6246
|
+
static builder() {
|
|
6247
|
+
return new RegisterCredentialArgsBuilder();
|
|
6248
|
+
}
|
|
6249
|
+
static fromBuilder(builder) {
|
|
6250
|
+
const buffer = builder.build();
|
|
6251
|
+
return _RegisterCredentialArgs.from_array(buffer);
|
|
6252
|
+
}
|
|
6253
|
+
get_wallet_account_idx() {
|
|
6254
|
+
const offset = 0;
|
|
6255
|
+
return this.view.getUint16(offset, true);
|
|
6256
|
+
}
|
|
6257
|
+
set_wallet_account_idx(value) {
|
|
6258
|
+
const offset = 0;
|
|
6259
|
+
this.view.setUint16(offset, value, true);
|
|
6260
|
+
}
|
|
6261
|
+
get wallet_account_idx() {
|
|
6262
|
+
return this.get_wallet_account_idx();
|
|
6263
|
+
}
|
|
6264
|
+
set wallet_account_idx(value) {
|
|
6265
|
+
this.set_wallet_account_idx(value);
|
|
6266
|
+
}
|
|
6267
|
+
get_lookup_account_idx() {
|
|
6268
|
+
const offset = 2;
|
|
6269
|
+
return this.view.getUint16(offset, true);
|
|
6270
|
+
}
|
|
6271
|
+
set_lookup_account_idx(value) {
|
|
6272
|
+
const offset = 2;
|
|
6273
|
+
this.view.setUint16(offset, value, true);
|
|
6274
|
+
}
|
|
6275
|
+
get lookup_account_idx() {
|
|
6276
|
+
return this.get_lookup_account_idx();
|
|
6277
|
+
}
|
|
6278
|
+
set lookup_account_idx(value) {
|
|
6279
|
+
this.set_lookup_account_idx(value);
|
|
6280
|
+
}
|
|
6281
|
+
get_seed() {
|
|
6282
|
+
const offset = 4;
|
|
6283
|
+
const slice = this.buffer.subarray(offset, offset + 32);
|
|
6284
|
+
return Seed32.from_array(slice);
|
|
6285
|
+
}
|
|
6286
|
+
set_seed(value) {
|
|
6287
|
+
const sourceBytes = value.buffer;
|
|
6288
|
+
const offset = 4;
|
|
6289
|
+
this.buffer.set(sourceBytes, offset);
|
|
6290
|
+
}
|
|
6291
|
+
get seed() {
|
|
6292
|
+
return this.get_seed();
|
|
6293
|
+
}
|
|
6294
|
+
set seed(value) {
|
|
6295
|
+
this.set_seed(value);
|
|
6296
|
+
}
|
|
6297
|
+
get_state_proof() {
|
|
6298
|
+
const offset = 36;
|
|
6299
|
+
const tail = this.buffer.subarray(offset);
|
|
6300
|
+
const validation = StateProof.validate(tail);
|
|
6301
|
+
if (!validation.ok || validation.consumed === void 0) {
|
|
6302
|
+
throw new Error("RegisterCredentialArgs: failed to read field 'state_proof' (invalid nested payload)");
|
|
6303
|
+
}
|
|
6304
|
+
const length = validation.consumed;
|
|
6305
|
+
const slice = tail.subarray(0, length);
|
|
6306
|
+
const opts = validation.params ? { params: validation.params } : void 0;
|
|
6307
|
+
return StateProof.from_array(slice, opts);
|
|
6308
|
+
}
|
|
6309
|
+
set_state_proof(value) {
|
|
6310
|
+
const sourceBytes = value.buffer;
|
|
6311
|
+
const offset = 36;
|
|
6312
|
+
this.buffer.set(sourceBytes, offset);
|
|
6313
|
+
}
|
|
6314
|
+
get state_proof() {
|
|
6315
|
+
return this.get_state_proof();
|
|
6316
|
+
}
|
|
6317
|
+
set state_proof(value) {
|
|
6318
|
+
this.set_state_proof(value);
|
|
6319
|
+
}
|
|
6320
|
+
static __tnFootprintInternal(__tnParams) {
|
|
6321
|
+
return __tnEvalFootprint3(__tn_ir_RegisterCredentialArgs.root, { params: __tnParams });
|
|
6322
|
+
}
|
|
6323
|
+
static __tnValidateInternal(buffer, __tnParams) {
|
|
6324
|
+
return __tnValidateIrTree3(__tn_ir_RegisterCredentialArgs, buffer, __tnParams);
|
|
6325
|
+
}
|
|
6326
|
+
static __tnInvokeFootprint(__tnParams) {
|
|
6327
|
+
return this.__tnFootprintInternal(__tnParams);
|
|
6328
|
+
}
|
|
6329
|
+
static __tnInvokeValidate(buffer, __tnParams) {
|
|
6330
|
+
return this.__tnValidateInternal(buffer, __tnParams);
|
|
6331
|
+
}
|
|
6332
|
+
static footprintIr() {
|
|
6333
|
+
return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
|
|
6334
|
+
}
|
|
6335
|
+
static footprint() {
|
|
6336
|
+
const irResult = this.footprintIr();
|
|
6337
|
+
const maxSafe = __tnToBigInt3(Number.MAX_SAFE_INTEGER);
|
|
6338
|
+
if (__tnBigIntGreaterThan3(irResult, maxSafe)) {
|
|
6339
|
+
throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for RegisterCredentialArgs");
|
|
6340
|
+
}
|
|
6341
|
+
return __tnBigIntToNumber3(irResult, "RegisterCredentialArgs::footprint");
|
|
6342
|
+
}
|
|
6343
|
+
static validate(_buffer, _opts) {
|
|
6344
|
+
__tnLogWarn3("RegisterCredentialArgs::validate falling back to basic length check");
|
|
6345
|
+
return { ok: true, consumed: _buffer.length };
|
|
6346
|
+
}
|
|
6347
|
+
static from_array(buffer) {
|
|
6348
|
+
if (!buffer || buffer.length === void 0) {
|
|
6349
|
+
return null;
|
|
6350
|
+
}
|
|
6351
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
6352
|
+
const validation = this.validate(buffer);
|
|
6353
|
+
if (!validation.ok) {
|
|
6354
|
+
return null;
|
|
6355
|
+
}
|
|
6356
|
+
return new _RegisterCredentialArgs(buffer);
|
|
6357
|
+
}
|
|
6358
|
+
};
|
|
6359
|
+
__tnRegisterFootprint3("RegisterCredentialArgs", (params) => RegisterCredentialArgs.__tnInvokeFootprint(params));
|
|
6360
|
+
__tnRegisterValidate3("RegisterCredentialArgs", (buffer, params) => RegisterCredentialArgs.__tnInvokeValidate(buffer, params));
|
|
6361
|
+
var RegisterCredentialArgsBuilder = class {
|
|
6362
|
+
constructor() {
|
|
6363
|
+
this.__tnTail_state_proof = null;
|
|
6364
|
+
this.buffer = new Uint8Array(36);
|
|
6365
|
+
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
6366
|
+
}
|
|
6367
|
+
__tnInvalidate() {
|
|
6368
|
+
}
|
|
6369
|
+
set_wallet_account_idx(value) {
|
|
6370
|
+
this.view.setUint16(0, value, true);
|
|
6371
|
+
this.__tnInvalidate();
|
|
6372
|
+
return this;
|
|
6373
|
+
}
|
|
6374
|
+
set_lookup_account_idx(value) {
|
|
6375
|
+
this.view.setUint16(2, value, true);
|
|
6376
|
+
this.__tnInvalidate();
|
|
6377
|
+
return this;
|
|
6378
|
+
}
|
|
6379
|
+
set_seed(value) {
|
|
6380
|
+
if (value.length !== 32) throw new Error("seed expects 32 bytes");
|
|
6381
|
+
this.buffer.set(value, 4);
|
|
6382
|
+
this.__tnInvalidate();
|
|
6383
|
+
return this;
|
|
6384
|
+
}
|
|
6385
|
+
set_state_proof(value) {
|
|
6386
|
+
const bytes = __tnResolveStructFieldInput(value, "RegisterCredentialArgsBuilder::state_proof");
|
|
6387
|
+
this.__tnTail_state_proof = bytes;
|
|
6388
|
+
this.__tnInvalidate();
|
|
6389
|
+
return this;
|
|
6390
|
+
}
|
|
6391
|
+
build() {
|
|
6392
|
+
const fragments = this.__tnCollectTailFragments();
|
|
6393
|
+
const size = this.__tnComputeSize(fragments);
|
|
6394
|
+
const buffer = new Uint8Array(size);
|
|
6395
|
+
this.__tnWriteInto(buffer, fragments);
|
|
6396
|
+
this.__tnValidateOrThrow(buffer);
|
|
6397
|
+
return buffer;
|
|
6398
|
+
}
|
|
6399
|
+
buildInto(target, offset = 0) {
|
|
6400
|
+
const fragments = this.__tnCollectTailFragments();
|
|
6401
|
+
const size = this.__tnComputeSize(fragments);
|
|
6402
|
+
if (target.length - offset < size) throw new Error("RegisterCredentialArgsBuilder: target buffer too small");
|
|
6403
|
+
const slice = target.subarray(offset, offset + size);
|
|
6404
|
+
this.__tnWriteInto(slice, fragments);
|
|
6405
|
+
this.__tnValidateOrThrow(slice);
|
|
6406
|
+
return target;
|
|
6407
|
+
}
|
|
6408
|
+
finish() {
|
|
6409
|
+
const buffer = this.build();
|
|
6410
|
+
const view = RegisterCredentialArgs.from_array(buffer);
|
|
6411
|
+
if (!view) throw new Error("RegisterCredentialArgsBuilder: failed to finalize view");
|
|
6412
|
+
return view;
|
|
6413
|
+
}
|
|
6414
|
+
finishView() {
|
|
6415
|
+
return this.finish();
|
|
6416
|
+
}
|
|
6417
|
+
__tnCollectTailFragments() {
|
|
6418
|
+
return [
|
|
6419
|
+
(() => {
|
|
6420
|
+
const bytes = this.__tnTail_state_proof;
|
|
6421
|
+
if (!bytes) throw new Error("RegisterCredentialArgsBuilder: field 'state_proof' must be set before build()");
|
|
6422
|
+
return bytes;
|
|
6423
|
+
})()
|
|
6424
|
+
];
|
|
6425
|
+
}
|
|
6426
|
+
__tnComputeSize(fragments) {
|
|
6427
|
+
let total = this.buffer.length;
|
|
6428
|
+
for (const fragment of fragments) {
|
|
6429
|
+
total += fragment.length;
|
|
6430
|
+
}
|
|
6431
|
+
return total;
|
|
6432
|
+
}
|
|
6433
|
+
__tnWriteInto(target, fragments) {
|
|
6434
|
+
target.set(this.buffer, 0);
|
|
6435
|
+
let cursor = this.buffer.length;
|
|
6436
|
+
for (const fragment of fragments) {
|
|
6437
|
+
target.set(fragment, cursor);
|
|
6438
|
+
cursor += fragment.length;
|
|
6439
|
+
}
|
|
6440
|
+
}
|
|
6441
|
+
__tnValidateOrThrow(buffer) {
|
|
6442
|
+
const result = RegisterCredentialArgs.validate(buffer);
|
|
6443
|
+
if (!result.ok) {
|
|
6444
|
+
throw new Error(`RegisterCredentialArgsBuilder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
|
|
6445
|
+
}
|
|
6446
|
+
}
|
|
6447
|
+
};
|
|
5994
6448
|
var __tn_ir_PasskeyInstruction = {
|
|
5995
6449
|
typeName: "PasskeyInstruction",
|
|
5996
6450
|
root: { op: "align", alignment: 1, node: { op: "add", left: { op: "align", alignment: 1, node: { op: "const", value: 1n } }, right: { op: "align", alignment: 1, node: { op: "field", param: "payload.payload_size" } } } }
|
|
@@ -6036,6 +6490,10 @@ var PasskeyInstruction_payload_Inner = class _PasskeyInstruction_payload_Inner {
|
|
|
6036
6490
|
if (!this.descriptor || this.descriptor.tag !== 5) return null;
|
|
6037
6491
|
return RemoveAuthorityArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? void 0 });
|
|
6038
6492
|
}
|
|
6493
|
+
asRegisterCredential() {
|
|
6494
|
+
if (!this.descriptor || this.descriptor.tag !== 6) return null;
|
|
6495
|
+
return RegisterCredentialArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? void 0 });
|
|
6496
|
+
}
|
|
6039
6497
|
};
|
|
6040
6498
|
var _PasskeyInstruction = class _PasskeyInstruction {
|
|
6041
6499
|
constructor(buffer, params) {
|
|
@@ -6099,6 +6557,8 @@ var _PasskeyInstruction = class _PasskeyInstruction {
|
|
|
6099
6557
|
break;
|
|
6100
6558
|
case 5:
|
|
6101
6559
|
break;
|
|
6560
|
+
case 6:
|
|
6561
|
+
break;
|
|
6102
6562
|
default:
|
|
6103
6563
|
return null;
|
|
6104
6564
|
}
|
|
@@ -6279,6 +6739,13 @@ _PasskeyInstruction.payloadVariantDescriptors = Object.freeze([
|
|
|
6279
6739
|
payloadSize: 1,
|
|
6280
6740
|
payloadType: "PasskeyInstruction::payload::remove_authority",
|
|
6281
6741
|
createPayloadBuilder: () => __tnMaybeCallBuilder(RemoveAuthorityArgs)
|
|
6742
|
+
},
|
|
6743
|
+
{
|
|
6744
|
+
name: "register_credential",
|
|
6745
|
+
tag: 6,
|
|
6746
|
+
payloadSize: null,
|
|
6747
|
+
payloadType: "PasskeyInstruction::payload::register_credential",
|
|
6748
|
+
createPayloadBuilder: () => __tnMaybeCallBuilder(RegisterCredentialArgs)
|
|
6282
6749
|
}
|
|
6283
6750
|
]);
|
|
6284
6751
|
var PasskeyInstruction = _PasskeyInstruction;
|
|
@@ -6494,6 +6961,20 @@ function encodeRemoveAuthorityInstruction(params) {
|
|
|
6494
6961
|
return new PasskeyInstructionBuilder().payload().select("remove_authority").writePayload(argsPayload).finish().build();
|
|
6495
6962
|
}
|
|
6496
6963
|
|
|
6964
|
+
// src/instructions/register-credential.ts
|
|
6965
|
+
function encodeRegisterCredentialInstruction(params) {
|
|
6966
|
+
const { walletAccountIdx, lookupAccountIdx, seed, stateProof } = params;
|
|
6967
|
+
if (seed.length !== 32) throw new Error("seed must be 32 bytes");
|
|
6968
|
+
if (walletAccountIdx < 0 || walletAccountIdx > 65535) {
|
|
6969
|
+
throw new Error("walletAccountIdx must be 0-65535");
|
|
6970
|
+
}
|
|
6971
|
+
if (lookupAccountIdx < 0 || lookupAccountIdx > 65535) {
|
|
6972
|
+
throw new Error("lookupAccountIdx must be 0-65535");
|
|
6973
|
+
}
|
|
6974
|
+
const argsPayload = new RegisterCredentialArgsBuilder().set_wallet_account_idx(walletAccountIdx).set_lookup_account_idx(lookupAccountIdx).set_seed(seed).set_state_proof(stateProof).build();
|
|
6975
|
+
return new PasskeyInstructionBuilder().payload().select("register_credential").writePayload(argsPayload).finish().build();
|
|
6976
|
+
}
|
|
6977
|
+
|
|
6497
6978
|
// src/instructions/shared.ts
|
|
6498
6979
|
function concatenateInstructions(instructions) {
|
|
6499
6980
|
const totalLength = instructions.reduce((sum, instr) => sum + instr.length, 0);
|
|
@@ -6556,6 +7037,18 @@ async function deriveWalletAddress(seed, programAddress) {
|
|
|
6556
7037
|
const hashBuffer = await crypto.subtle.digest("SHA-256", preimage);
|
|
6557
7038
|
return new Uint8Array(hashBuffer);
|
|
6558
7039
|
}
|
|
7040
|
+
async function createCredentialLookupSeed(credentialId, walletName) {
|
|
7041
|
+
const nameBytes = new TextEncoder().encode(walletName);
|
|
7042
|
+
const data = new Uint8Array(credentialId.length + nameBytes.length);
|
|
7043
|
+
data.set(credentialId, 0);
|
|
7044
|
+
data.set(nameBytes, credentialId.length);
|
|
7045
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
7046
|
+
return new Uint8Array(hashBuffer);
|
|
7047
|
+
}
|
|
7048
|
+
async function deriveCredentialLookupAddress(credentialId, walletName, programAddress) {
|
|
7049
|
+
const seed = await createCredentialLookupSeed(credentialId, walletName);
|
|
7050
|
+
return deriveWalletAddress(seed, programAddress);
|
|
7051
|
+
}
|
|
6559
7052
|
|
|
6560
7053
|
// src/context.ts
|
|
6561
7054
|
var import_helpers2 = require("@thru/helpers");
|
|
@@ -6762,6 +7255,7 @@ function bigIntToBytesBE(value, length) {
|
|
|
6762
7255
|
INSTRUCTION_ADD_AUTHORITY,
|
|
6763
7256
|
INSTRUCTION_CREATE,
|
|
6764
7257
|
INSTRUCTION_INVOKE,
|
|
7258
|
+
INSTRUCTION_REGISTER_CREDENTIAL,
|
|
6765
7259
|
INSTRUCTION_REMOVE_AUTHORITY,
|
|
6766
7260
|
INSTRUCTION_TRANSFER,
|
|
6767
7261
|
INSTRUCTION_VALIDATE,
|
|
@@ -6780,12 +7274,15 @@ function bigIntToBytesBE(value, length) {
|
|
|
6780
7274
|
bytesToHex,
|
|
6781
7275
|
compareBytes,
|
|
6782
7276
|
concatenateInstructions,
|
|
7277
|
+
createCredentialLookupSeed,
|
|
6783
7278
|
createValidateChallenge,
|
|
6784
7279
|
createWalletSeed,
|
|
7280
|
+
deriveCredentialLookupAddress,
|
|
6785
7281
|
deriveWalletAddress,
|
|
6786
7282
|
encodeAddAuthorityInstruction,
|
|
6787
7283
|
encodeCreateInstruction,
|
|
6788
7284
|
encodeInvokeInstruction,
|
|
7285
|
+
encodeRegisterCredentialInstruction,
|
|
6789
7286
|
encodeRemoveAuthorityInstruction,
|
|
6790
7287
|
encodeTransferInstruction,
|
|
6791
7288
|
encodeValidateInstruction,
|