@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.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// src/constants.ts
|
|
2
|
-
var PASSKEY_MANAGER_PROGRAM_ADDRESS = "
|
|
2
|
+
var PASSKEY_MANAGER_PROGRAM_ADDRESS = "taUDdQyFxvM5i0HFRkEK3W45kWLyblAHSnMg4zplgUnz6Z";
|
|
3
3
|
var INSTRUCTION_CREATE = 0;
|
|
4
4
|
var INSTRUCTION_VALIDATE = 1;
|
|
5
5
|
var INSTRUCTION_TRANSFER = 2;
|
|
6
6
|
var INSTRUCTION_INVOKE = 3;
|
|
7
7
|
var INSTRUCTION_ADD_AUTHORITY = 4;
|
|
8
8
|
var INSTRUCTION_REMOVE_AUTHORITY = 5;
|
|
9
|
+
var INSTRUCTION_REGISTER_CREDENTIAL = 6;
|
|
9
10
|
var AUTHORITY_TAG_PASSKEY = 1;
|
|
10
11
|
var AUTHORITY_TAG_PUBKEY = 2;
|
|
11
12
|
|
|
@@ -5030,6 +5031,229 @@ var AddAuthorityArgsBuilder = class {
|
|
|
5030
5031
|
return view;
|
|
5031
5032
|
}
|
|
5032
5033
|
};
|
|
5034
|
+
var __tn_ir_CredentialLookup = {
|
|
5035
|
+
typeName: "CredentialLookup",
|
|
5036
|
+
root: { op: "const", value: 32n }
|
|
5037
|
+
};
|
|
5038
|
+
var CredentialLookup = class _CredentialLookup {
|
|
5039
|
+
constructor(buffer) {
|
|
5040
|
+
this.buffer = buffer;
|
|
5041
|
+
this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
5042
|
+
}
|
|
5043
|
+
static __tnCreateView(buffer, opts) {
|
|
5044
|
+
if (!buffer || buffer.length === void 0) throw new Error("CredentialLookup.__tnCreateView requires a Uint8Array");
|
|
5045
|
+
return new _CredentialLookup(new Uint8Array(buffer));
|
|
5046
|
+
}
|
|
5047
|
+
static builder() {
|
|
5048
|
+
return new CredentialLookupBuilder();
|
|
5049
|
+
}
|
|
5050
|
+
static fromBuilder(builder) {
|
|
5051
|
+
const buffer = builder.build();
|
|
5052
|
+
return _CredentialLookup.from_array(buffer);
|
|
5053
|
+
}
|
|
5054
|
+
get_wallet() {
|
|
5055
|
+
const offset = 0;
|
|
5056
|
+
const slice = this.buffer.subarray(offset, offset + 32);
|
|
5057
|
+
return Pubkey.from_array(slice);
|
|
5058
|
+
}
|
|
5059
|
+
set_wallet(value) {
|
|
5060
|
+
const sourceBytes = value.buffer;
|
|
5061
|
+
const offset = 0;
|
|
5062
|
+
this.buffer.set(sourceBytes, offset);
|
|
5063
|
+
}
|
|
5064
|
+
get wallet() {
|
|
5065
|
+
return this.get_wallet();
|
|
5066
|
+
}
|
|
5067
|
+
set wallet(value) {
|
|
5068
|
+
this.set_wallet(value);
|
|
5069
|
+
}
|
|
5070
|
+
static __tnFootprintInternal(__tnParams) {
|
|
5071
|
+
return __tnEvalFootprint3(__tn_ir_CredentialLookup.root, { params: __tnParams });
|
|
5072
|
+
}
|
|
5073
|
+
static __tnValidateInternal(buffer, __tnParams) {
|
|
5074
|
+
return __tnValidateIrTree3(__tn_ir_CredentialLookup, buffer, __tnParams);
|
|
5075
|
+
}
|
|
5076
|
+
static __tnInvokeFootprint(__tnParams) {
|
|
5077
|
+
return this.__tnFootprintInternal(__tnParams);
|
|
5078
|
+
}
|
|
5079
|
+
static __tnInvokeValidate(buffer, __tnParams) {
|
|
5080
|
+
return this.__tnValidateInternal(buffer, __tnParams);
|
|
5081
|
+
}
|
|
5082
|
+
static footprintIr() {
|
|
5083
|
+
return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
|
|
5084
|
+
}
|
|
5085
|
+
static footprint() {
|
|
5086
|
+
const irResult = this.footprintIr();
|
|
5087
|
+
const maxSafe = __tnToBigInt3(Number.MAX_SAFE_INTEGER);
|
|
5088
|
+
if (__tnBigIntGreaterThan3(irResult, maxSafe)) {
|
|
5089
|
+
throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for CredentialLookup");
|
|
5090
|
+
}
|
|
5091
|
+
return __tnBigIntToNumber3(irResult, "CredentialLookup::footprint");
|
|
5092
|
+
}
|
|
5093
|
+
static validate(buffer, _opts) {
|
|
5094
|
+
if (buffer.length < 32) return { ok: false, code: "tn.buffer_too_small", consumed: 32 };
|
|
5095
|
+
return { ok: true, consumed: 32 };
|
|
5096
|
+
}
|
|
5097
|
+
static from_array(buffer) {
|
|
5098
|
+
if (!buffer || buffer.length === void 0) {
|
|
5099
|
+
return null;
|
|
5100
|
+
}
|
|
5101
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
5102
|
+
const validation = this.validate(buffer);
|
|
5103
|
+
if (!validation.ok) {
|
|
5104
|
+
return null;
|
|
5105
|
+
}
|
|
5106
|
+
return new _CredentialLookup(buffer);
|
|
5107
|
+
}
|
|
5108
|
+
};
|
|
5109
|
+
__tnRegisterFootprint3("CredentialLookup", (params) => CredentialLookup.__tnInvokeFootprint(params));
|
|
5110
|
+
__tnRegisterValidate3("CredentialLookup", (buffer, params) => CredentialLookup.__tnInvokeValidate(buffer, params));
|
|
5111
|
+
var CredentialLookupBuilder = class {
|
|
5112
|
+
constructor() {
|
|
5113
|
+
this.buffer = new Uint8Array(32);
|
|
5114
|
+
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
5115
|
+
}
|
|
5116
|
+
set_wallet(value) {
|
|
5117
|
+
if (value.length !== 32) throw new Error("wallet expects 32 bytes");
|
|
5118
|
+
this.buffer.set(value, 0);
|
|
5119
|
+
return this;
|
|
5120
|
+
}
|
|
5121
|
+
build() {
|
|
5122
|
+
return this.buffer.slice();
|
|
5123
|
+
}
|
|
5124
|
+
buildInto(target, offset = 0) {
|
|
5125
|
+
if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
|
|
5126
|
+
target.set(this.buffer, offset);
|
|
5127
|
+
return target;
|
|
5128
|
+
}
|
|
5129
|
+
finish() {
|
|
5130
|
+
const view = CredentialLookup.from_array(this.buffer.slice());
|
|
5131
|
+
if (!view) throw new Error("failed to build CredentialLookup");
|
|
5132
|
+
return view;
|
|
5133
|
+
}
|
|
5134
|
+
};
|
|
5135
|
+
var __tn_ir_CredentialRegisteredEventData = {
|
|
5136
|
+
typeName: "CredentialRegisteredEventData",
|
|
5137
|
+
root: { op: "const", value: 64n }
|
|
5138
|
+
};
|
|
5139
|
+
var CredentialRegisteredEventData = class _CredentialRegisteredEventData {
|
|
5140
|
+
constructor(buffer) {
|
|
5141
|
+
this.buffer = buffer;
|
|
5142
|
+
this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
5143
|
+
}
|
|
5144
|
+
static __tnCreateView(buffer, opts) {
|
|
5145
|
+
if (!buffer || buffer.length === void 0) throw new Error("CredentialRegisteredEventData.__tnCreateView requires a Uint8Array");
|
|
5146
|
+
return new _CredentialRegisteredEventData(new Uint8Array(buffer));
|
|
5147
|
+
}
|
|
5148
|
+
static builder() {
|
|
5149
|
+
return new CredentialRegisteredEventDataBuilder();
|
|
5150
|
+
}
|
|
5151
|
+
static fromBuilder(builder) {
|
|
5152
|
+
const buffer = builder.build();
|
|
5153
|
+
return _CredentialRegisteredEventData.from_array(buffer);
|
|
5154
|
+
}
|
|
5155
|
+
get_wallet() {
|
|
5156
|
+
const offset = 0;
|
|
5157
|
+
const slice = this.buffer.subarray(offset, offset + 32);
|
|
5158
|
+
return Pubkey.from_array(slice);
|
|
5159
|
+
}
|
|
5160
|
+
set_wallet(value) {
|
|
5161
|
+
const sourceBytes = value.buffer;
|
|
5162
|
+
const offset = 0;
|
|
5163
|
+
this.buffer.set(sourceBytes, offset);
|
|
5164
|
+
}
|
|
5165
|
+
get wallet() {
|
|
5166
|
+
return this.get_wallet();
|
|
5167
|
+
}
|
|
5168
|
+
set wallet(value) {
|
|
5169
|
+
this.set_wallet(value);
|
|
5170
|
+
}
|
|
5171
|
+
get_lookup() {
|
|
5172
|
+
const offset = 32;
|
|
5173
|
+
const slice = this.buffer.subarray(offset, offset + 32);
|
|
5174
|
+
return Pubkey.from_array(slice);
|
|
5175
|
+
}
|
|
5176
|
+
set_lookup(value) {
|
|
5177
|
+
const sourceBytes = value.buffer;
|
|
5178
|
+
const offset = 32;
|
|
5179
|
+
this.buffer.set(sourceBytes, offset);
|
|
5180
|
+
}
|
|
5181
|
+
get lookup() {
|
|
5182
|
+
return this.get_lookup();
|
|
5183
|
+
}
|
|
5184
|
+
set lookup(value) {
|
|
5185
|
+
this.set_lookup(value);
|
|
5186
|
+
}
|
|
5187
|
+
static __tnFootprintInternal(__tnParams) {
|
|
5188
|
+
return __tnEvalFootprint3(__tn_ir_CredentialRegisteredEventData.root, { params: __tnParams });
|
|
5189
|
+
}
|
|
5190
|
+
static __tnValidateInternal(buffer, __tnParams) {
|
|
5191
|
+
return __tnValidateIrTree3(__tn_ir_CredentialRegisteredEventData, buffer, __tnParams);
|
|
5192
|
+
}
|
|
5193
|
+
static __tnInvokeFootprint(__tnParams) {
|
|
5194
|
+
return this.__tnFootprintInternal(__tnParams);
|
|
5195
|
+
}
|
|
5196
|
+
static __tnInvokeValidate(buffer, __tnParams) {
|
|
5197
|
+
return this.__tnValidateInternal(buffer, __tnParams);
|
|
5198
|
+
}
|
|
5199
|
+
static footprintIr() {
|
|
5200
|
+
return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
|
|
5201
|
+
}
|
|
5202
|
+
static footprint() {
|
|
5203
|
+
const irResult = this.footprintIr();
|
|
5204
|
+
const maxSafe = __tnToBigInt3(Number.MAX_SAFE_INTEGER);
|
|
5205
|
+
if (__tnBigIntGreaterThan3(irResult, maxSafe)) {
|
|
5206
|
+
throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for CredentialRegisteredEventData");
|
|
5207
|
+
}
|
|
5208
|
+
return __tnBigIntToNumber3(irResult, "CredentialRegisteredEventData::footprint");
|
|
5209
|
+
}
|
|
5210
|
+
static validate(buffer, _opts) {
|
|
5211
|
+
if (buffer.length < 64) return { ok: false, code: "tn.buffer_too_small", consumed: 64 };
|
|
5212
|
+
return { ok: true, consumed: 64 };
|
|
5213
|
+
}
|
|
5214
|
+
static from_array(buffer) {
|
|
5215
|
+
if (!buffer || buffer.length === void 0) {
|
|
5216
|
+
return null;
|
|
5217
|
+
}
|
|
5218
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
5219
|
+
const validation = this.validate(buffer);
|
|
5220
|
+
if (!validation.ok) {
|
|
5221
|
+
return null;
|
|
5222
|
+
}
|
|
5223
|
+
return new _CredentialRegisteredEventData(buffer);
|
|
5224
|
+
}
|
|
5225
|
+
};
|
|
5226
|
+
__tnRegisterFootprint3("CredentialRegisteredEventData", (params) => CredentialRegisteredEventData.__tnInvokeFootprint(params));
|
|
5227
|
+
__tnRegisterValidate3("CredentialRegisteredEventData", (buffer, params) => CredentialRegisteredEventData.__tnInvokeValidate(buffer, params));
|
|
5228
|
+
var CredentialRegisteredEventDataBuilder = class {
|
|
5229
|
+
constructor() {
|
|
5230
|
+
this.buffer = new Uint8Array(64);
|
|
5231
|
+
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
5232
|
+
}
|
|
5233
|
+
set_wallet(value) {
|
|
5234
|
+
if (value.length !== 32) throw new Error("wallet expects 32 bytes");
|
|
5235
|
+
this.buffer.set(value, 0);
|
|
5236
|
+
return this;
|
|
5237
|
+
}
|
|
5238
|
+
set_lookup(value) {
|
|
5239
|
+
if (value.length !== 32) throw new Error("lookup expects 32 bytes");
|
|
5240
|
+
this.buffer.set(value, 32);
|
|
5241
|
+
return this;
|
|
5242
|
+
}
|
|
5243
|
+
build() {
|
|
5244
|
+
return this.buffer.slice();
|
|
5245
|
+
}
|
|
5246
|
+
buildInto(target, offset = 0) {
|
|
5247
|
+
if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
|
|
5248
|
+
target.set(this.buffer, offset);
|
|
5249
|
+
return target;
|
|
5250
|
+
}
|
|
5251
|
+
finish() {
|
|
5252
|
+
const view = CredentialRegisteredEventData.from_array(this.buffer.slice());
|
|
5253
|
+
if (!view) throw new Error("failed to build CredentialRegisteredEventData");
|
|
5254
|
+
return view;
|
|
5255
|
+
}
|
|
5256
|
+
};
|
|
5033
5257
|
var __tn_ir_InvokeArgs = {
|
|
5034
5258
|
typeName: "InvokeArgs",
|
|
5035
5259
|
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 } } } } }
|
|
@@ -5370,7 +5594,7 @@ var InvokeArgsBuilder = class {
|
|
|
5370
5594
|
};
|
|
5371
5595
|
var __tn_ir_PasskeyEvent = {
|
|
5372
5596
|
typeName: "PasskeyEvent",
|
|
5373
|
-
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 } } }] } } } }
|
|
5597
|
+
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 } } }] } } } }
|
|
5374
5598
|
};
|
|
5375
5599
|
var PasskeyEvent_payload_Inner = class _PasskeyEvent_payload_Inner {
|
|
5376
5600
|
constructor(buffer, descriptor, fieldContext) {
|
|
@@ -5401,6 +5625,10 @@ var PasskeyEvent_payload_Inner = class _PasskeyEvent_payload_Inner {
|
|
|
5401
5625
|
if (!this.descriptor || this.descriptor.tag !== 2) return null;
|
|
5402
5626
|
return WalletTransferEventData.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? void 0 });
|
|
5403
5627
|
}
|
|
5628
|
+
asCredentialRegistered() {
|
|
5629
|
+
if (!this.descriptor || this.descriptor.tag !== 3) return null;
|
|
5630
|
+
return CredentialRegisteredEventData.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? void 0 });
|
|
5631
|
+
}
|
|
5404
5632
|
};
|
|
5405
5633
|
var _PasskeyEvent = class _PasskeyEvent {
|
|
5406
5634
|
constructor(buffer, params) {
|
|
@@ -5579,6 +5807,13 @@ _PasskeyEvent.payloadVariantDescriptors = Object.freeze([
|
|
|
5579
5807
|
payloadSize: 72,
|
|
5580
5808
|
payloadType: "PasskeyEvent::payload::wallet_transfer",
|
|
5581
5809
|
createPayloadBuilder: () => __tnMaybeCallBuilder(WalletTransferEventData)
|
|
5810
|
+
},
|
|
5811
|
+
{
|
|
5812
|
+
name: "credential_registered",
|
|
5813
|
+
tag: 3,
|
|
5814
|
+
payloadSize: 64,
|
|
5815
|
+
payloadType: "PasskeyEvent::payload::credential_registered",
|
|
5816
|
+
createPayloadBuilder: () => __tnMaybeCallBuilder(CredentialRegisteredEventData)
|
|
5582
5817
|
}
|
|
5583
5818
|
]);
|
|
5584
5819
|
var PasskeyEvent = _PasskeyEvent;
|
|
@@ -5926,6 +6161,221 @@ var CreateArgsBuilder = class {
|
|
|
5926
6161
|
}
|
|
5927
6162
|
}
|
|
5928
6163
|
};
|
|
6164
|
+
var __tn_ir_RegisterCredentialArgs = {
|
|
6165
|
+
typeName: "RegisterCredentialArgs",
|
|
6166
|
+
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" }] } } } }
|
|
6167
|
+
};
|
|
6168
|
+
var RegisterCredentialArgs = class _RegisterCredentialArgs {
|
|
6169
|
+
constructor(buffer) {
|
|
6170
|
+
this.buffer = buffer;
|
|
6171
|
+
this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
6172
|
+
}
|
|
6173
|
+
static __tnCreateView(buffer, opts) {
|
|
6174
|
+
if (!buffer || buffer.length === void 0) throw new Error("RegisterCredentialArgs.__tnCreateView requires a Uint8Array");
|
|
6175
|
+
return new _RegisterCredentialArgs(new Uint8Array(buffer));
|
|
6176
|
+
}
|
|
6177
|
+
static builder() {
|
|
6178
|
+
return new RegisterCredentialArgsBuilder();
|
|
6179
|
+
}
|
|
6180
|
+
static fromBuilder(builder) {
|
|
6181
|
+
const buffer = builder.build();
|
|
6182
|
+
return _RegisterCredentialArgs.from_array(buffer);
|
|
6183
|
+
}
|
|
6184
|
+
get_wallet_account_idx() {
|
|
6185
|
+
const offset = 0;
|
|
6186
|
+
return this.view.getUint16(offset, true);
|
|
6187
|
+
}
|
|
6188
|
+
set_wallet_account_idx(value) {
|
|
6189
|
+
const offset = 0;
|
|
6190
|
+
this.view.setUint16(offset, value, true);
|
|
6191
|
+
}
|
|
6192
|
+
get wallet_account_idx() {
|
|
6193
|
+
return this.get_wallet_account_idx();
|
|
6194
|
+
}
|
|
6195
|
+
set wallet_account_idx(value) {
|
|
6196
|
+
this.set_wallet_account_idx(value);
|
|
6197
|
+
}
|
|
6198
|
+
get_lookup_account_idx() {
|
|
6199
|
+
const offset = 2;
|
|
6200
|
+
return this.view.getUint16(offset, true);
|
|
6201
|
+
}
|
|
6202
|
+
set_lookup_account_idx(value) {
|
|
6203
|
+
const offset = 2;
|
|
6204
|
+
this.view.setUint16(offset, value, true);
|
|
6205
|
+
}
|
|
6206
|
+
get lookup_account_idx() {
|
|
6207
|
+
return this.get_lookup_account_idx();
|
|
6208
|
+
}
|
|
6209
|
+
set lookup_account_idx(value) {
|
|
6210
|
+
this.set_lookup_account_idx(value);
|
|
6211
|
+
}
|
|
6212
|
+
get_seed() {
|
|
6213
|
+
const offset = 4;
|
|
6214
|
+
const slice = this.buffer.subarray(offset, offset + 32);
|
|
6215
|
+
return Seed32.from_array(slice);
|
|
6216
|
+
}
|
|
6217
|
+
set_seed(value) {
|
|
6218
|
+
const sourceBytes = value.buffer;
|
|
6219
|
+
const offset = 4;
|
|
6220
|
+
this.buffer.set(sourceBytes, offset);
|
|
6221
|
+
}
|
|
6222
|
+
get seed() {
|
|
6223
|
+
return this.get_seed();
|
|
6224
|
+
}
|
|
6225
|
+
set seed(value) {
|
|
6226
|
+
this.set_seed(value);
|
|
6227
|
+
}
|
|
6228
|
+
get_state_proof() {
|
|
6229
|
+
const offset = 36;
|
|
6230
|
+
const tail = this.buffer.subarray(offset);
|
|
6231
|
+
const validation = StateProof.validate(tail);
|
|
6232
|
+
if (!validation.ok || validation.consumed === void 0) {
|
|
6233
|
+
throw new Error("RegisterCredentialArgs: failed to read field 'state_proof' (invalid nested payload)");
|
|
6234
|
+
}
|
|
6235
|
+
const length = validation.consumed;
|
|
6236
|
+
const slice = tail.subarray(0, length);
|
|
6237
|
+
const opts = validation.params ? { params: validation.params } : void 0;
|
|
6238
|
+
return StateProof.from_array(slice, opts);
|
|
6239
|
+
}
|
|
6240
|
+
set_state_proof(value) {
|
|
6241
|
+
const sourceBytes = value.buffer;
|
|
6242
|
+
const offset = 36;
|
|
6243
|
+
this.buffer.set(sourceBytes, offset);
|
|
6244
|
+
}
|
|
6245
|
+
get state_proof() {
|
|
6246
|
+
return this.get_state_proof();
|
|
6247
|
+
}
|
|
6248
|
+
set state_proof(value) {
|
|
6249
|
+
this.set_state_proof(value);
|
|
6250
|
+
}
|
|
6251
|
+
static __tnFootprintInternal(__tnParams) {
|
|
6252
|
+
return __tnEvalFootprint3(__tn_ir_RegisterCredentialArgs.root, { params: __tnParams });
|
|
6253
|
+
}
|
|
6254
|
+
static __tnValidateInternal(buffer, __tnParams) {
|
|
6255
|
+
return __tnValidateIrTree3(__tn_ir_RegisterCredentialArgs, buffer, __tnParams);
|
|
6256
|
+
}
|
|
6257
|
+
static __tnInvokeFootprint(__tnParams) {
|
|
6258
|
+
return this.__tnFootprintInternal(__tnParams);
|
|
6259
|
+
}
|
|
6260
|
+
static __tnInvokeValidate(buffer, __tnParams) {
|
|
6261
|
+
return this.__tnValidateInternal(buffer, __tnParams);
|
|
6262
|
+
}
|
|
6263
|
+
static footprintIr() {
|
|
6264
|
+
return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
|
|
6265
|
+
}
|
|
6266
|
+
static footprint() {
|
|
6267
|
+
const irResult = this.footprintIr();
|
|
6268
|
+
const maxSafe = __tnToBigInt3(Number.MAX_SAFE_INTEGER);
|
|
6269
|
+
if (__tnBigIntGreaterThan3(irResult, maxSafe)) {
|
|
6270
|
+
throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for RegisterCredentialArgs");
|
|
6271
|
+
}
|
|
6272
|
+
return __tnBigIntToNumber3(irResult, "RegisterCredentialArgs::footprint");
|
|
6273
|
+
}
|
|
6274
|
+
static validate(_buffer, _opts) {
|
|
6275
|
+
__tnLogWarn3("RegisterCredentialArgs::validate falling back to basic length check");
|
|
6276
|
+
return { ok: true, consumed: _buffer.length };
|
|
6277
|
+
}
|
|
6278
|
+
static from_array(buffer) {
|
|
6279
|
+
if (!buffer || buffer.length === void 0) {
|
|
6280
|
+
return null;
|
|
6281
|
+
}
|
|
6282
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
6283
|
+
const validation = this.validate(buffer);
|
|
6284
|
+
if (!validation.ok) {
|
|
6285
|
+
return null;
|
|
6286
|
+
}
|
|
6287
|
+
return new _RegisterCredentialArgs(buffer);
|
|
6288
|
+
}
|
|
6289
|
+
};
|
|
6290
|
+
__tnRegisterFootprint3("RegisterCredentialArgs", (params) => RegisterCredentialArgs.__tnInvokeFootprint(params));
|
|
6291
|
+
__tnRegisterValidate3("RegisterCredentialArgs", (buffer, params) => RegisterCredentialArgs.__tnInvokeValidate(buffer, params));
|
|
6292
|
+
var RegisterCredentialArgsBuilder = class {
|
|
6293
|
+
constructor() {
|
|
6294
|
+
this.__tnTail_state_proof = null;
|
|
6295
|
+
this.buffer = new Uint8Array(36);
|
|
6296
|
+
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
6297
|
+
}
|
|
6298
|
+
__tnInvalidate() {
|
|
6299
|
+
}
|
|
6300
|
+
set_wallet_account_idx(value) {
|
|
6301
|
+
this.view.setUint16(0, value, true);
|
|
6302
|
+
this.__tnInvalidate();
|
|
6303
|
+
return this;
|
|
6304
|
+
}
|
|
6305
|
+
set_lookup_account_idx(value) {
|
|
6306
|
+
this.view.setUint16(2, value, true);
|
|
6307
|
+
this.__tnInvalidate();
|
|
6308
|
+
return this;
|
|
6309
|
+
}
|
|
6310
|
+
set_seed(value) {
|
|
6311
|
+
if (value.length !== 32) throw new Error("seed expects 32 bytes");
|
|
6312
|
+
this.buffer.set(value, 4);
|
|
6313
|
+
this.__tnInvalidate();
|
|
6314
|
+
return this;
|
|
6315
|
+
}
|
|
6316
|
+
set_state_proof(value) {
|
|
6317
|
+
const bytes = __tnResolveStructFieldInput(value, "RegisterCredentialArgsBuilder::state_proof");
|
|
6318
|
+
this.__tnTail_state_proof = bytes;
|
|
6319
|
+
this.__tnInvalidate();
|
|
6320
|
+
return this;
|
|
6321
|
+
}
|
|
6322
|
+
build() {
|
|
6323
|
+
const fragments = this.__tnCollectTailFragments();
|
|
6324
|
+
const size = this.__tnComputeSize(fragments);
|
|
6325
|
+
const buffer = new Uint8Array(size);
|
|
6326
|
+
this.__tnWriteInto(buffer, fragments);
|
|
6327
|
+
this.__tnValidateOrThrow(buffer);
|
|
6328
|
+
return buffer;
|
|
6329
|
+
}
|
|
6330
|
+
buildInto(target, offset = 0) {
|
|
6331
|
+
const fragments = this.__tnCollectTailFragments();
|
|
6332
|
+
const size = this.__tnComputeSize(fragments);
|
|
6333
|
+
if (target.length - offset < size) throw new Error("RegisterCredentialArgsBuilder: target buffer too small");
|
|
6334
|
+
const slice = target.subarray(offset, offset + size);
|
|
6335
|
+
this.__tnWriteInto(slice, fragments);
|
|
6336
|
+
this.__tnValidateOrThrow(slice);
|
|
6337
|
+
return target;
|
|
6338
|
+
}
|
|
6339
|
+
finish() {
|
|
6340
|
+
const buffer = this.build();
|
|
6341
|
+
const view = RegisterCredentialArgs.from_array(buffer);
|
|
6342
|
+
if (!view) throw new Error("RegisterCredentialArgsBuilder: failed to finalize view");
|
|
6343
|
+
return view;
|
|
6344
|
+
}
|
|
6345
|
+
finishView() {
|
|
6346
|
+
return this.finish();
|
|
6347
|
+
}
|
|
6348
|
+
__tnCollectTailFragments() {
|
|
6349
|
+
return [
|
|
6350
|
+
(() => {
|
|
6351
|
+
const bytes = this.__tnTail_state_proof;
|
|
6352
|
+
if (!bytes) throw new Error("RegisterCredentialArgsBuilder: field 'state_proof' must be set before build()");
|
|
6353
|
+
return bytes;
|
|
6354
|
+
})()
|
|
6355
|
+
];
|
|
6356
|
+
}
|
|
6357
|
+
__tnComputeSize(fragments) {
|
|
6358
|
+
let total = this.buffer.length;
|
|
6359
|
+
for (const fragment of fragments) {
|
|
6360
|
+
total += fragment.length;
|
|
6361
|
+
}
|
|
6362
|
+
return total;
|
|
6363
|
+
}
|
|
6364
|
+
__tnWriteInto(target, fragments) {
|
|
6365
|
+
target.set(this.buffer, 0);
|
|
6366
|
+
let cursor = this.buffer.length;
|
|
6367
|
+
for (const fragment of fragments) {
|
|
6368
|
+
target.set(fragment, cursor);
|
|
6369
|
+
cursor += fragment.length;
|
|
6370
|
+
}
|
|
6371
|
+
}
|
|
6372
|
+
__tnValidateOrThrow(buffer) {
|
|
6373
|
+
const result = RegisterCredentialArgs.validate(buffer);
|
|
6374
|
+
if (!result.ok) {
|
|
6375
|
+
throw new Error(`RegisterCredentialArgsBuilder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
|
|
6376
|
+
}
|
|
6377
|
+
}
|
|
6378
|
+
};
|
|
5929
6379
|
var __tn_ir_PasskeyInstruction = {
|
|
5930
6380
|
typeName: "PasskeyInstruction",
|
|
5931
6381
|
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" } } } }
|
|
@@ -5971,6 +6421,10 @@ var PasskeyInstruction_payload_Inner = class _PasskeyInstruction_payload_Inner {
|
|
|
5971
6421
|
if (!this.descriptor || this.descriptor.tag !== 5) return null;
|
|
5972
6422
|
return RemoveAuthorityArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? void 0 });
|
|
5973
6423
|
}
|
|
6424
|
+
asRegisterCredential() {
|
|
6425
|
+
if (!this.descriptor || this.descriptor.tag !== 6) return null;
|
|
6426
|
+
return RegisterCredentialArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? void 0 });
|
|
6427
|
+
}
|
|
5974
6428
|
};
|
|
5975
6429
|
var _PasskeyInstruction = class _PasskeyInstruction {
|
|
5976
6430
|
constructor(buffer, params) {
|
|
@@ -6034,6 +6488,8 @@ var _PasskeyInstruction = class _PasskeyInstruction {
|
|
|
6034
6488
|
break;
|
|
6035
6489
|
case 5:
|
|
6036
6490
|
break;
|
|
6491
|
+
case 6:
|
|
6492
|
+
break;
|
|
6037
6493
|
default:
|
|
6038
6494
|
return null;
|
|
6039
6495
|
}
|
|
@@ -6214,6 +6670,13 @@ _PasskeyInstruction.payloadVariantDescriptors = Object.freeze([
|
|
|
6214
6670
|
payloadSize: 1,
|
|
6215
6671
|
payloadType: "PasskeyInstruction::payload::remove_authority",
|
|
6216
6672
|
createPayloadBuilder: () => __tnMaybeCallBuilder(RemoveAuthorityArgs)
|
|
6673
|
+
},
|
|
6674
|
+
{
|
|
6675
|
+
name: "register_credential",
|
|
6676
|
+
tag: 6,
|
|
6677
|
+
payloadSize: null,
|
|
6678
|
+
payloadType: "PasskeyInstruction::payload::register_credential",
|
|
6679
|
+
createPayloadBuilder: () => __tnMaybeCallBuilder(RegisterCredentialArgs)
|
|
6217
6680
|
}
|
|
6218
6681
|
]);
|
|
6219
6682
|
var PasskeyInstruction = _PasskeyInstruction;
|
|
@@ -6429,6 +6892,20 @@ function encodeRemoveAuthorityInstruction(params) {
|
|
|
6429
6892
|
return new PasskeyInstructionBuilder().payload().select("remove_authority").writePayload(argsPayload).finish().build();
|
|
6430
6893
|
}
|
|
6431
6894
|
|
|
6895
|
+
// src/instructions/register-credential.ts
|
|
6896
|
+
function encodeRegisterCredentialInstruction(params) {
|
|
6897
|
+
const { walletAccountIdx, lookupAccountIdx, seed, stateProof } = params;
|
|
6898
|
+
if (seed.length !== 32) throw new Error("seed must be 32 bytes");
|
|
6899
|
+
if (walletAccountIdx < 0 || walletAccountIdx > 65535) {
|
|
6900
|
+
throw new Error("walletAccountIdx must be 0-65535");
|
|
6901
|
+
}
|
|
6902
|
+
if (lookupAccountIdx < 0 || lookupAccountIdx > 65535) {
|
|
6903
|
+
throw new Error("lookupAccountIdx must be 0-65535");
|
|
6904
|
+
}
|
|
6905
|
+
const argsPayload = new RegisterCredentialArgsBuilder().set_wallet_account_idx(walletAccountIdx).set_lookup_account_idx(lookupAccountIdx).set_seed(seed).set_state_proof(stateProof).build();
|
|
6906
|
+
return new PasskeyInstructionBuilder().payload().select("register_credential").writePayload(argsPayload).finish().build();
|
|
6907
|
+
}
|
|
6908
|
+
|
|
6432
6909
|
// src/instructions/shared.ts
|
|
6433
6910
|
function concatenateInstructions(instructions) {
|
|
6434
6911
|
const totalLength = instructions.reduce((sum, instr) => sum + instr.length, 0);
|
|
@@ -6491,6 +6968,18 @@ async function deriveWalletAddress(seed, programAddress) {
|
|
|
6491
6968
|
const hashBuffer = await crypto.subtle.digest("SHA-256", preimage);
|
|
6492
6969
|
return new Uint8Array(hashBuffer);
|
|
6493
6970
|
}
|
|
6971
|
+
async function createCredentialLookupSeed(credentialId, walletName) {
|
|
6972
|
+
const nameBytes = new TextEncoder().encode(walletName);
|
|
6973
|
+
const data = new Uint8Array(credentialId.length + nameBytes.length);
|
|
6974
|
+
data.set(credentialId, 0);
|
|
6975
|
+
data.set(nameBytes, credentialId.length);
|
|
6976
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
6977
|
+
return new Uint8Array(hashBuffer);
|
|
6978
|
+
}
|
|
6979
|
+
async function deriveCredentialLookupAddress(credentialId, walletName, programAddress) {
|
|
6980
|
+
const seed = await createCredentialLookupSeed(credentialId, walletName);
|
|
6981
|
+
return deriveWalletAddress(seed, programAddress);
|
|
6982
|
+
}
|
|
6494
6983
|
|
|
6495
6984
|
// src/context.ts
|
|
6496
6985
|
import { encodeAddress, decodeAddress as decodeAddress2 } from "@thru/helpers";
|
|
@@ -6696,6 +7185,7 @@ export {
|
|
|
6696
7185
|
INSTRUCTION_ADD_AUTHORITY,
|
|
6697
7186
|
INSTRUCTION_CREATE,
|
|
6698
7187
|
INSTRUCTION_INVOKE,
|
|
7188
|
+
INSTRUCTION_REGISTER_CREDENTIAL,
|
|
6699
7189
|
INSTRUCTION_REMOVE_AUTHORITY,
|
|
6700
7190
|
INSTRUCTION_TRANSFER,
|
|
6701
7191
|
INSTRUCTION_VALIDATE,
|
|
@@ -6714,12 +7204,15 @@ export {
|
|
|
6714
7204
|
bytesToHex,
|
|
6715
7205
|
compareBytes,
|
|
6716
7206
|
concatenateInstructions,
|
|
7207
|
+
createCredentialLookupSeed,
|
|
6717
7208
|
createValidateChallenge,
|
|
6718
7209
|
createWalletSeed,
|
|
7210
|
+
deriveCredentialLookupAddress,
|
|
6719
7211
|
deriveWalletAddress,
|
|
6720
7212
|
encodeAddAuthorityInstruction,
|
|
6721
7213
|
encodeCreateInstruction,
|
|
6722
7214
|
encodeInvokeInstruction,
|
|
7215
|
+
encodeRegisterCredentialInstruction,
|
|
6723
7216
|
encodeRemoveAuthorityInstruction,
|
|
6724
7217
|
encodeTransferInstruction,
|
|
6725
7218
|
encodeValidateInstruction,
|