Skip to content

Commit fb8abe0

Browse files
committed
add signRaw method
1 parent db1fcac commit fb8abe0

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export const enum INS {
3131
ALLOWLIST_UPLOAD = 0x93,
3232
}
3333

34+
export type INS_SIGN = INS.SIGN | INS.SIGN_RAW;
35+
3436
export const enum PAYLOAD_TYPE {
3537
INIT = 0x00,
3638
ADD = 0x01,

src/substrate_app.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
type ResponseSign,
3030
type ResponseVersion,
3131
SCHEME,
32+
type INS_SIGN,
3233
} from "./common";
3334

3435
export class SubstrateApp {
@@ -168,7 +169,13 @@ export class SubstrateApp {
168169
}, processErrorResponse);
169170
}
170171

171-
async signSendChunk(chunkIdx: number, chunkNum: number, chunk: any, scheme = SCHEME.ED25519) {
172+
async signSendChunk(
173+
chunkIdx: number,
174+
chunkNum: number,
175+
chunk: Buffer,
176+
scheme = SCHEME.ED25519,
177+
ins: INS_SIGN = INS.SIGN
178+
) {
172179
let payloadType = PAYLOAD_TYPE.ADD;
173180
if (chunkIdx === 1) {
174181
payloadType = PAYLOAD_TYPE.INIT;
@@ -181,7 +188,7 @@ export class SubstrateApp {
181188
if (!isNaN(scheme)) p2 = scheme;
182189

183190
return await this.transport
184-
.send(this.cla, INS.SIGN, payloadType, p2, chunk, [ERROR_CODE.NoError, 0x6984, 0x6a80])
191+
.send(this.cla, ins, payloadType, p2, chunk, [ERROR_CODE.NoError, 0x6984, 0x6a80])
185192
.then((response) => {
186193
const errorCodeData = response.subarray(-2);
187194
const returnCode = errorCodeData[0] * 256 + errorCodeData[1];
@@ -202,15 +209,16 @@ export class SubstrateApp {
202209
}, processErrorResponse);
203210
}
204211

205-
async sign(
212+
async signImpl(
206213
account: number,
207214
change: number,
208215
addressIndex: number,
209216
message: Buffer,
217+
ins: INS_SIGN,
210218
scheme = SCHEME.ED25519
211219
): Promise<ResponseSign> {
212220
const chunks = SubstrateApp.signGetChunks(this.slip0044, account, change, addressIndex, message);
213-
return await this.signSendChunk(1, chunks.length, chunks[0], scheme).then(async () => {
221+
return await this.signSendChunk(1, chunks.length, chunks[0], scheme, ins).then(async () => {
214222
let result;
215223
for (let i = 1; i < chunks.length; i += 1) {
216224
result = await this.signSendChunk(1 + i, chunks.length, chunks[i], scheme);
@@ -227,6 +235,14 @@ export class SubstrateApp {
227235
}, processErrorResponse);
228236
}
229237

238+
async sign(account: number, change: number, addressIndex: number, message: Buffer, scheme = SCHEME.ED25519) {
239+
return await this.signImpl(account, change, addressIndex, message, INS.SIGN, scheme);
240+
}
241+
242+
async signRaw(account: number, change: number, addressIndex: number, message: Buffer, scheme = SCHEME.ED25519) {
243+
return await this.signImpl(account, change, addressIndex, message, INS.SIGN_RAW, scheme);
244+
}
245+
230246
/// Allow list related commands. They are NOT available on all apps
231247

232248
async getAllowlistPubKey(): Promise<ResponseAllowlistPubKey> {

0 commit comments

Comments
 (0)